Skip to content

Commit

Permalink
Remove noqa
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Dec 22, 2023
1 parent 7cf1cdb commit 61f35d1
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 34 deletions.
8 changes: 4 additions & 4 deletions tests/test_base_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"

Expand All @@ -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()
Expand All @@ -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"


Expand Down
6 changes: 3 additions & 3 deletions tests/test_database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_log_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/test_run_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/test_server_support_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_slurm_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ 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


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(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_slurm_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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?

Expand Down

0 comments on commit 61f35d1

Please sign in to comment.