"""The app's Api without a window: library create/open, settings, and jobs running in the worker thread.""" import time import pytest from mygarmin import app from test_pipeline import inbox # noqa: F401 (fixture) def wait(api): for _ in range(600): if not api._busy: return time.sleep(0.05) raise TimeoutError(api._busy) def test_app_api(tmp_path, inbox, monkeypatch): monkeypatch.setattr(app, 'STATE', str(tmp_path / 'app.json')) api = app.Api() assert api.state()['library'] is None s = api.create_library(str(tmp_path / 'lib'), 'Sam', '1990', 'F', 'Europe/London') assert s['library']['settings']['name'] == 'Sam' and s['recent'] == [str(tmp_path / 'lib')] assert api.import_paths([str(inbox)])['ok'] assert not api.build()['ok'] # one job at a time wait(api) st = api.state()['library'] assert st['shown'] == 4 and st['health']['days'] == 2 and st['dashboard'] assert api.export()['ok']; wait(api) assert api.state()['library']['exports'] s = api.save_settings('Sam B', '1990', 'F', 'Europe/London', 'C:\\x\\a.html\n\n') assert s['library']['settings']['copy_dashboard_to'] == ['C:\\x\\a.html'] assert app.Api().state()['library']['root'] == str(tmp_path / 'lib') # reopens the last library assert api.open_library(str(tmp_path))['error']