From 856fbf3dfea3f2c607627a62a28fe3b8b84d445f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Dec 2023 17:17:15 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_base_scheduler.py | 8 ++++---- tests/test_database_manager.py | 6 +++--- tests/test_launcher.py | 2 +- tests/test_log_generation.py | 2 +- tests/test_run_manager.py | 8 ++++---- tests/test_server_support_common.py | 6 +++--- tests/test_slurm_run.py | 6 +++--- tests/test_slurm_scheduler.py | 8 ++++---- tests/test_utils.py | 14 +++++++------- tests/test_widgets.py | 8 ++++---- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/test_base_scheduler.py b/tests/test_base_scheduler.py index d4153e2b..f0b80ade 100644 --- a/tests/test_base_scheduler.py +++ b/tests/test_base_scheduler.py @@ -49,7 +49,7 @@ def test_base_scheduler_job_script() -> None: def test_base_scheduler() -> None: """Test that the base scheduler is set correctly.""" s = MockScheduler(cores=4) - assert s.cores == 4 # noqa: PLR2004 + assert s.cores == 4 def test_queue() -> None: @@ -59,7 +59,7 @@ def test_queue() -> None: scheduler.start_job("test_job2") queue_info = scheduler.queue() - assert len(queue_info) == 2 # noqa: PLR2004 + assert len(queue_info) == 2 assert queue_info["0"]["job_name"] == "test_job1" assert queue_info["1"]["job_name"] == "test_job2" @@ -69,7 +69,7 @@ def test_cancel() -> None: scheduler = MockScheduler(cores=2) scheduler.start_job("test_job1") scheduler.start_job("test_job2") - assert len(scheduler.queue()) == 2 # noqa: PLR2004 + assert len(scheduler.queue()) == 2 scheduler.cancel(["test_job1"]) queue_info = scheduler.queue() @@ -86,7 +86,7 @@ def test_update_queue() -> None: scheduler.update_queue("test_job1", "COMPLETED") queue_info = scheduler.queue() - assert len(queue_info) == 2 # noqa: PLR2004 + assert len(queue_info) == 2 assert queue_info[j1]["status"] == "COMPLETED" diff --git a/tests/test_database_manager.py b/tests/test_database_manager.py index 8e1c0f75..90fd29e5 100644 --- a/tests/test_database_manager.py +++ b/tests/test_database_manager.py @@ -38,7 +38,7 @@ def test_simple_database_insert_multiple(tmp_path: Path) -> None: _DBEntry(fname="file3.txt"), ] db.insert_multiple(entries) - assert len(db.all()) == 3 # noqa: PLR2004 + assert len(db.all()) == 3 def test_simple_database_update(tmp_path: Path) -> None: @@ -66,7 +66,7 @@ def test_simple_database_count(tmp_path: Path) -> None: ] db.insert_multiple(entries) count_done = db.count(lambda entry: entry.is_done) - assert count_done == 2 # noqa: PLR2004 + assert count_done == 2 def test_simple_database_get_and_contains(tmp_path: Path) -> None: @@ -96,7 +96,7 @@ def test_simple_database_get_all(tmp_path: Path) -> None: ] db.insert_multiple(entries) done_entries = db.get_all(lambda entry: entry.is_done) - assert len(done_entries) == 2 # noqa: PLR2004 + assert len(done_entries) == 2 assert done_entries[0][1].fname == "file1.txt" assert done_entries[1][1].fname == "file3.txt" diff --git a/tests/test_launcher.py b/tests/test_launcher.py index f360531e..5508dfe5 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -35,7 +35,7 @@ def test_parse_args() -> None: # Call _parse_args and check the results args = launcher._parse_args() - assert args.n == 4 # noqa: PLR2004 + assert args.n == 4 assert args.name == "test" # Restore the original sys.argv diff --git a/tests/test_log_generation.py b/tests/test_log_generation.py index 6dcfa70b..60c68b8c 100644 --- a/tests/test_log_generation.py +++ b/tests/test_log_generation.py @@ -79,7 +79,7 @@ async def test_log_info( if log_task.done(): assert log_task.exception() is None await asyncio.sleep(0.1) - if len(caplog.records) > 10: # noqa: PLR2004 + if len(caplog.records) > 10: break # Filter the captured log records based on level and logger name diff --git a/tests/test_run_manager.py b/tests/test_run_manager.py index 3cd8bd8e..b8d0e03e 100644 --- a/tests/test_run_manager.py +++ b/tests/test_run_manager.py @@ -201,7 +201,7 @@ async def test_start_one_by_one( """Test starting RunManagers one by one.""" def goal(rm: RunManager) -> bool: - return rm.elapsed_time() >= 2 # noqa: PLR2004 + return rm.elapsed_time() >= 2 rm1 = RunManager(mock_scheduler, learners[:1], fnames[:1], job_name="rm1") rm2 = RunManager(mock_scheduler, learners[1:], fnames[1:], job_name="rm2") @@ -210,7 +210,7 @@ def goal(rm: RunManager) -> bool: tasks = start_one_by_one(rm1, rm2, goal=goal) await asyncio.sleep(0.2) assert isinstance(tasks, tuple) - assert len(tasks) == 2 # noqa: PLR2004 + assert len(tasks) == 2 assert isinstance(tasks[0], asyncio.Future) assert isinstance(tasks[1], list) assert isinstance(tasks[1][0], asyncio.Future) @@ -290,7 +290,7 @@ async def test_run_manager_auto_restart( # Check if the new job is started in the database db = rm.database_manager.as_dicts() - assert len(db) == 2 # noqa: PLR2004 + assert len(db) == 2 jobs = [ ("2", "log2.log", job_name0), (job_id1, "log1.log", job_name1), @@ -311,7 +311,7 @@ async def test_run_manager_auto_restart( # Check that the jobs are now done db = rm.database_manager.as_dicts() - assert len(db) == 2 # noqa: PLR2004 + assert len(db) == 2 for i, (_, log_fname, _) in enumerate(jobs): assert db[i]["job_id"] is None assert db[i]["job_name"] is None diff --git a/tests/test_server_support_common.py b/tests/test_server_support_common.py index 7ddf9276..183b3bd0 100644 --- a/tests/test_server_support_common.py +++ b/tests/test_server_support_common.py @@ -46,12 +46,12 @@ def test_cleanup_scheduler_files(mock_scheduler: MockScheduler, tmp_path: Path) (tmp_path / f"{name}-JOBID.out").touch() (tmp_path / f"{name}-JOBID.log").touch() - assert len(list(tmp_path.glob("*"))) == 6 # noqa: PLR2004 + assert len(list(tmp_path.glob("*"))) == 6 move_to = tmp_path / "moved" with temporary_working_directory(tmp_path): cleanup_scheduler_files(job_names, mock_scheduler, move_to=move_to) assert len(list(tmp_path.glob("*"))) == 1 - assert len(list(move_to.glob("*"))) == 6 # noqa: PLR2004 + assert len(list(move_to.glob("*"))) == 6 def test__get_all_files(mock_scheduler: MockScheduler, tmp_path: Path) -> None: @@ -63,7 +63,7 @@ def test__get_all_files(mock_scheduler: MockScheduler, tmp_path: Path) -> None: (tmp_path / f"{name}-JOBID.log").touch() with temporary_working_directory(tmp_path): all_files = _get_all_files(job_names, mock_scheduler) - assert len(all_files) == 6 # noqa: PLR2004 + assert len(all_files) == 6 def test__ipython_profiles() -> None: diff --git a/tests/test_slurm_run.py b/tests/test_slurm_run.py index a23f450b..3987bf33 100644 --- a/tests/test_slurm_run.py +++ b/tests/test_slurm_run.py @@ -41,8 +41,8 @@ def test_slurm_run_with_default_arguments( rm = slurm_run(learners, fnames) assert isinstance(rm, RunManager) assert isinstance(rm.scheduler, SLURM) - assert rm.save_interval == 300 # noqa: PLR2004 - assert rm.log_interval == 300 # noqa: PLR2004 + assert rm.save_interval == 300 + assert rm.log_interval == 300 assert rm.learners == learners assert rm.fnames == fnames assert rm.scheduler.exclusive is True @@ -50,7 +50,7 @@ def test_slurm_run_with_default_arguments( def goal_example(learner: adaptive.Learner1D) -> bool: """Example goal function for testing.""" - return len(learner.data) >= 10 # noqa: PLR2004 + return len(learner.data) >= 10 @pytest.mark.parametrize( diff --git a/tests/test_slurm_scheduler.py b/tests/test_slurm_scheduler.py index d4feaea5..b580bbb2 100644 --- a/tests/test_slurm_scheduler.py +++ b/tests/test_slurm_scheduler.py @@ -41,7 +41,7 @@ def test_init_nodes_cores_per_node() -> None: def test_slurm_scheduler() -> None: """Test that the slurm scheduler is set correctly.""" s = SLURM(cores=4) - assert s._cores == 4 # noqa: PLR2004 + assert s._cores == 4 assert s.nodes is None assert s.cores_per_node is None @@ -52,9 +52,9 @@ def test_slurm_scheduler_nodes_cores_per_node() -> None: s = SLURM(nodes=2, cores_per_node=2, partition="nc24-low") assert s.partition == "nc24-low" assert s._cores is None - assert s.cores == 4 # noqa: PLR2004 - assert s.nodes == 2 # noqa: PLR2004 - assert s.cores_per_node == 2 # noqa: PLR2004 + assert s.cores == 4 + assert s.nodes == 2 + assert s.cores_per_node == 2 def test_getstate_setstate() -> None: diff --git a/tests/test_utils.py b/tests/test_utils.py index 200f137b..4c3fc67b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -153,15 +153,15 @@ def test_add_constant_to_fname() -> None: def test_maybe_round() -> None: """Test `utils.maybe_round`.""" - assert utils.maybe_round(3.14159265, 3) == 3.14 # noqa: PLR2004 + assert utils.maybe_round(3.14159265, 3) == 3.14 assert utils.maybe_round(1 + 2j, 3) == 1 + 2j assert utils.maybe_round("test", 3) == "test" def test_round_sigfigs() -> None: """Test `utils.round_sigfigs`.""" - assert utils.round_sigfigs(3.14159265, 3) == 3.14 # noqa: PLR2004 - assert utils.round_sigfigs(123456789, 3) == 123000000 # noqa: PLR2004 + assert utils.round_sigfigs(3.14159265, 3) == 3.14 + assert utils.round_sigfigs(123456789, 3) == 123000000 def test_remove_or_move_files(tmp_path: Path) -> None: @@ -225,14 +225,14 @@ def cached_function(x: float) -> float: return x**2 assert cached_function.cache_dict == {} - assert cached_function(2) == 4 # noqa: PLR2004 + assert cached_function(2) == 4 assert ( cached_function.cache_dict == {"{'x': 2}": 4} if sys.version_info >= (3, 9) else {"OrderedDict([('x', 2)])": 4} ) - assert cached_function(3) == 9 # noqa: PLR2004 + assert cached_function(3) == 9 assert ( cached_function.cache_dict == {"{'x': 2}": 4, "{'x': 3}": 9} if sys.version_info >= (3, 9) @@ -245,7 +245,7 @@ def test_smart_goal() -> None: learner = adaptive.Learner1D(lambda x: x, bounds=(-10, 10)) goal_callable = utils.smart_goal( - lambda lrn: lrn.npoints >= 10, # noqa: PLR2004 + lambda lrn: lrn.npoints >= 10, [learner], ) assert not goal_callable(learner) @@ -606,7 +606,7 @@ def square(x: int) -> int: fut = ex.submit(wrapped_function, 4) result = fut.result() - assert result == 16, f"Expected 16, but got {result}" # noqa: PLR2004 + assert result == 16, f"Expected 16, but got {result}" # Check if the global cache contains the key in the executor fut_is_key = ex.submit(_is_key_in_global_cache, wrapped_function._cache_key) diff --git a/tests/test_widgets.py b/tests/test_widgets.py index ccf9515d..4b333100 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -185,10 +185,10 @@ def test_get_fnames(tmp_path: Path) -> None: run_manager = MockRunManager(tmp_path) fnames = _get_fnames(run_manager, only_running=False) # type: ignore[arg-type] - assert len(fnames) == 2 # noqa: PLR2004 + assert len(fnames) == 2 fnames = _get_fnames(run_manager, only_running=True) # type: ignore[arg-type] - assert len(fnames) == 6 # noqa: PLR2004 + assert len(fnames) == 6 def test_failed_job_logs(tmp_path: Path) -> None: @@ -272,7 +272,7 @@ def test_get_fnames_only_running(tmp_path: Path) -> None: """Test the _get_fnames function with only_running=True.""" run_manager = MockRunManager(tmp_path) fnames = _get_fnames(run_manager, only_running=True) # type: ignore[arg-type] - assert len(fnames) == 6 # noqa: PLR2004 + assert len(fnames) == 6 def test_get_fnames_only_running_false(tmp_path: Path) -> None: @@ -282,7 +282,7 @@ def test_get_fnames_only_running_false(tmp_path: Path) -> None: with open(log_fname, "w") as f: # noqa: PTH123 f.write("This is a test log file.") fnames = _get_fnames(run_manager, only_running=False) # type: ignore[arg-type] - assert len(fnames) == 3 # noqa: PLR2004 + assert len(fnames) == 3 # TODO: it is picking up the database file and scheduler file # we should probably filter those out?