From 91b167fc43185b935d7369e7622698c9c82b6f75 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Mon, 27 May 2024 10:30:56 -0400 Subject: [PATCH 1/4] Fix spell checker errors --- tests/scenarios/test_disable.py | 64 ++++++++------- tests/scenarios/test_last_report.py | 36 ++++---- tests/scenarios/test_multiprocessing.py | 66 ++++++++------- tests/scenarios/test_readme_quick_start.py | 96 +++++++++++----------- 4 files changed, 135 insertions(+), 127 deletions(-) diff --git a/tests/scenarios/test_disable.py b/tests/scenarios/test_disable.py index b3355ea..59cb7a9 100644 --- a/tests/scenarios/test_disable.py +++ b/tests/scenarios/test_disable.py @@ -12,12 +12,12 @@ from .conftest import MockCreatePresentation -@pytest.mark.parametrize('niterations', [10, 1, 0]) +@pytest.mark.parametrize('n_iterations', [10, 1, 0]) def test_one_loop( - mock_create_presentation: MockCreatePresentation, niterations: int + mock_create_presentation: MockCreatePresentation, n_iterations: int ) -> None: disable() - for i in atpbar(range(niterations)): + for i in atpbar(range(n_iterations)): pass presentations = mock_create_presentation.presentations assert 0 == len(presentations) @@ -30,15 +30,15 @@ def test_nested_loops(mock_create_presentation: MockCreatePresentation) -> None: pass -def run_with_threading(nthreads: int = 3, niterations: list[int] = [5, 5, 5]) -> None: +def run_with_threading(n_threads: int = 3, n_iterations: list[int] = [5, 5, 5]) -> None: def task(n: int, name: str) -> None: for i in atpbar(range(n), name=name): time.sleep(0.0001) threads = [] - for i in range(nthreads): + for i in range(n_threads): name = 'thread {}'.format(i) - n = niterations[i] + n = n_iterations[i] t = threading.Thread(target=task, args=(n, name)) t.start() threads.append(t) @@ -47,30 +47,30 @@ def task(n: int, name: str) -> None: flush() -@pytest.mark.parametrize('niterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) -@pytest.mark.parametrize('nthreads', [3, 1, 0]) +@pytest.mark.parametrize('n_iterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) +@pytest.mark.parametrize('n_threads', [3, 1, 0]) def test_threading( mock_create_presentation: MockCreatePresentation, - nthreads: int, - niterations: list[int], + n_threads: int, + n_iterations: list[int], ) -> None: disable() - # make niterations as long as nthreads. repeat if necessary - niterations = list( + # make n_iterations as long as n_threads. repeat if necessary + n_iterations = list( itertools.chain( - *itertools.repeat(niterations, nthreads // len(niterations) + 1) + *itertools.repeat(n_iterations, n_threads // len(n_iterations) + 1) ) - )[:nthreads] + )[:n_threads] - run_with_threading(nthreads, niterations) + run_with_threading(n_threads, n_iterations) presentations = mock_create_presentation.presentations assert 0 == len(presentations) def run_with_multiprocessing( - nprocesses: int, ntasks: int, niterations: list[int] + n_processes: int, n_tasks: int, n_iterations: list[int] ) -> None: def task(n: int, name: str) -> None: for i in atpbar(range(n), name=name): @@ -92,37 +92,39 @@ def worker( reporter = find_reporter() queue = multiprocessing.JoinableQueue() # type: ignore - for i in range(nprocesses): + for i in range(n_processes): p = multiprocessing.Process(target=worker, args=(reporter, task, queue)) p.start() - for i in range(ntasks): + for i in range(n_tasks): name = 'task {}'.format(i) - n = niterations[i] + n = n_iterations[i] queue.put((n, name)) - for i in range(nprocesses): + for i in range(n_processes): queue.put(None) queue.join() flush() @pytest.mark.xfail() -@pytest.mark.parametrize('niterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) -@pytest.mark.parametrize('ntasks', [3, 1, 0]) -@pytest.mark.parametrize('nprocesses', [4, 1]) +@pytest.mark.parametrize('n_iterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) +@pytest.mark.parametrize('n_tasks', [3, 1, 0]) +@pytest.mark.parametrize('n_processes', [4, 1]) def test_multiprocessing( mock_create_presentation: MockCreatePresentation, - nprocesses: int, - ntasks: int, - niterations: list[int], + n_processes: int, + n_tasks: int, + n_iterations: list[int], ) -> None: disable() - # make niterations as long as ntasks. repeat if necessary - niterations = list( - itertools.chain(*itertools.repeat(niterations, ntasks // len(niterations) + 1)) - )[:ntasks] + # make n_iterations as long as n_tasks. repeat if necessary + n_iterations = list( + itertools.chain( + *itertools.repeat(n_iterations, n_tasks // len(n_iterations) + 1) + ) + )[:n_tasks] - run_with_multiprocessing(nprocesses, ntasks, niterations) + run_with_multiprocessing(n_processes, n_tasks, n_iterations) presentations = mock_create_presentation.presentations assert 0 == len(presentations) diff --git a/tests/scenarios/test_last_report.py b/tests/scenarios/test_last_report.py index d6ca981..d56d436 100644 --- a/tests/scenarios/test_last_report.py +++ b/tests/scenarios/test_last_report.py @@ -9,51 +9,51 @@ @pytest.mark.parametrize('method', ['break', 'exception']) -@pytest.mark.parametrize('niterations', [10, 1, 0]) -@pytest.mark.parametrize('ndones', [10, 4, 1, 0]) +@pytest.mark.parametrize('n_iterations', [10, 1, 0]) +@pytest.mark.parametrize('n_done', [10, 4, 1, 0]) def test_one_loop_break_exception( mock_create_presentation: MockCreatePresentation, - niterations: int, - ndones: int, + n_iterations: int, + n_done: int, method: Literal['break', 'exception'], ) -> None: - ndones = min(ndones, niterations) + n_done = min(n_done, n_iterations) - def task_break(ndones: int, niterations: int) -> None: - for i in atpbar(range(niterations)): - if i == ndones: + def task_break(n_done: int, n_iterations: int) -> None: + for i in atpbar(range(n_iterations)): + if i == n_done: break - def task_exception(ndones: int, niterations: int) -> None: - for i in atpbar(range(niterations)): - if i == ndones: + def task_exception(n_done: int, n_iterations: int) -> None: + for i in atpbar(range(n_iterations)): + if i == n_done: raise Exception() # if method == 'break': - task_break(ndones, niterations) + task_break(n_done, n_iterations) else: - if ndones < niterations: + if n_done < n_iterations: with pytest.raises(Exception): - task_exception(ndones, niterations) + task_exception(n_done, n_iterations) else: - task_exception(ndones, niterations) + task_exception(n_done, n_iterations) ## print() ## print(mock_create_presentation) - nreports_expected = ndones + 1 + bool(ndones < niterations) + n_reports_expected = n_done + 1 + bool(n_done < n_iterations) presentations = mock_create_presentation.presentations assert 2 == len(presentations) # created when atpbar started and ended # progressbar0 = presentations[0] - assert nreports_expected == len(progressbar0.reports) + assert n_reports_expected == len(progressbar0.reports) assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.n_firsts assert 1 == progressbar0.n_lasts - done_total_list_expected = [(ndones, niterations)] + done_total_list_expected = [(n_done, n_iterations)] done_total_list_actual = [ (d['done'], d['total']) for d in progressbar0._report_dict.values() ] diff --git a/tests/scenarios/test_multiprocessing.py b/tests/scenarios/test_multiprocessing.py index 5f71b68..3f55bab 100644 --- a/tests/scenarios/test_multiprocessing.py +++ b/tests/scenarios/test_multiprocessing.py @@ -12,7 +12,7 @@ def run_with_multiprocessing( - nprocesses: int, ntasks: int, niterations: list[int], time_starting_task: float + n_processes: int, n_tasks: int, n_iterations: list[int], time_starting_task: float ) -> None: def task(n: int, name: str, time_starting: float) -> None: @@ -37,17 +37,17 @@ def worker( reporter = find_reporter() queue = multiprocessing.JoinableQueue() # type: ignore - for i in range(nprocesses): + for i in range(n_processes): p = multiprocessing.Process(target=worker, args=(reporter, task, queue)) p.start() - for i in atpbar(range(ntasks)): # `atpbar` is used here + for i in atpbar(range(n_tasks)): # `atpbar` is used here name = 'task {}'.format(i) - n = niterations[i] + n = n_iterations[i] queue.put((n, name, time_starting_task)) time.sleep(0.01) - for i in range(nprocesses): + for i in range(n_processes): queue.put(None) queue.join() @@ -56,40 +56,42 @@ def worker( @pytest.mark.xfail() @pytest.mark.parametrize('time_starting_task', [0, 0.01, 0.2]) -@pytest.mark.parametrize('niterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) -@pytest.mark.parametrize('ntasks', [3, 1, 0]) -@pytest.mark.parametrize('nprocesses', [6, 2, 1]) +@pytest.mark.parametrize('n_iterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) +@pytest.mark.parametrize('n_tasks', [3, 1, 0]) +@pytest.mark.parametrize('n_processes', [6, 2, 1]) def test_multiprocessing_from_loop( mock_create_presentation: MockCreatePresentation, - nprocesses: int, - ntasks: int, - niterations: list[int], + n_processes: int, + n_tasks: int, + n_iterations: list[int], time_starting_task: float, ) -> None: - # make niterations as long as ntasks. repeat if necessary - niterations = list( - itertools.chain(*itertools.repeat(niterations, ntasks // len(niterations) + 1)) - )[:ntasks] + # make n_iterations as long as n_tasks. repeat if necessary + n_iterations = list( + itertools.chain( + *itertools.repeat(n_iterations, n_tasks // len(n_iterations) + 1) + ) + )[:n_tasks] - run_with_multiprocessing(nprocesses, ntasks, niterations, time_starting_task) + run_with_multiprocessing(n_processes, n_tasks, n_iterations, time_starting_task) ## print() ## print(mock_create_presentation) - nreports_expected_from_main = ntasks + 1 - nreports_expected_from_tasks = sum(niterations) + ntasks - nreports_expected = nreports_expected_from_main + nreports_expected_from_tasks + n_reports_expected_from_main = n_tasks + 1 + n_reports_expected_from_tasks = sum(n_iterations) + n_tasks + n_reports_expected = n_reports_expected_from_main + n_reports_expected_from_tasks presentations = mock_create_presentation.presentations - if nreports_expected_from_tasks == 0: + if n_reports_expected_from_tasks == 0: assert 3 == len(presentations) # in find_reporter(), at the # end of `atpbar` in the main # process, and in flush(). progressbar0 = presentations[0] - assert nreports_expected == len(progressbar0.reports) + assert n_reports_expected == len(progressbar0.reports) # one report from `atpbar` in the main thread assert 1 == progressbar0.n_firsts @@ -103,10 +105,10 @@ def test_multiprocessing_from_loop( assert 0 == len(progressbar1.reports) progressbar0 = presentations[0] - assert ntasks + 1 == len(progressbar0.task_ids) - assert ntasks + 1 == progressbar0.n_firsts - assert ntasks + 1 == progressbar0.n_lasts - assert nreports_expected == len(progressbar0.reports) + assert n_tasks + 1 == len(progressbar0.task_ids) + assert n_tasks + 1 == progressbar0.n_firsts + assert n_tasks + 1 == progressbar0.n_lasts + assert n_reports_expected == len(progressbar0.reports) else: assert 3 == len(presentations) @@ -117,19 +119,21 @@ def test_multiprocessing_from_loop( progressbar0 = presentations[0] progressbar1 = presentations[1] - assert ntasks + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) - assert ntasks + 1 == progressbar0.n_firsts + progressbar1.n_firsts - assert ntasks + 1 == progressbar0.n_lasts + progressbar1.n_lasts - assert nreports_expected == len(progressbar0.reports) + len( + assert n_tasks + 1 == len(progressbar0.task_ids) + len( + progressbar1.task_ids + ) + assert n_tasks + 1 == progressbar0.n_firsts + progressbar1.n_firsts + assert n_tasks + 1 == progressbar0.n_lasts + progressbar1.n_lasts + assert n_reports_expected == len(progressbar0.reports) + len( progressbar1.reports ) # At this point the pickup shouldn't be owned. Therefore, a new # `atpbar` in the main thread should own it. - npresentations = len(presentations) + n_presentations = len(presentations) for i in atpbar(range(4)): pass - assert npresentations + 1 == len(presentations) + assert n_presentations + 1 == len(presentations) progressbar = presentations[-2] assert 1 == len(progressbar.task_ids) assert 1 == progressbar.n_firsts diff --git a/tests/scenarios/test_readme_quick_start.py b/tests/scenarios/test_readme_quick_start.py index f3b2219..3cfc815 100644 --- a/tests/scenarios/test_readme_quick_start.py +++ b/tests/scenarios/test_readme_quick_start.py @@ -1,8 +1,8 @@ -from collections.abc import Callable import itertools import multiprocessing import threading import time +from collections.abc import Callable import pytest @@ -12,17 +12,17 @@ from .conftest import MockCreatePresentation -@pytest.mark.parametrize('niterations', [10, 1, 0]) +@pytest.mark.parametrize('n_iterations', [10, 1, 0]) def test_one_loop( mock_create_presentation: MockCreatePresentation, - niterations: int, + n_iterations: int, ) -> None: - for i in atpbar(range(niterations)): + for i in atpbar(range(n_iterations)): pass # - nreports_expected = niterations + 1 + n_reports_expected = n_iterations + 1 presentations = mock_create_presentation.presentations # @@ -30,7 +30,7 @@ def test_one_loop( # progressbar0 = presentations[0] - assert nreports_expected == len(progressbar0.reports) + assert n_reports_expected == len(progressbar0.reports) assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.n_firsts assert 1 == progressbar0.n_lasts @@ -59,15 +59,15 @@ def test_nested_loops(mock_create_presentation: MockCreatePresentation) -> None: assert 0 == len(progressbar1.reports) -def run_with_threading(nthreads: int = 3, niterations: list[int] = [5, 5, 5]) -> None: +def run_with_threading(n_threads: int = 3, n_iterations: list[int] = [5, 5, 5]) -> None: def task(n: int, name: str) -> None: for i in atpbar(range(n), name=name): time.sleep(0.0001) threads = [] - for i in range(nthreads): + for i in range(n_threads): name = 'thread {}'.format(i) - n = niterations[i] + n = n_iterations[i] t = threading.Thread(target=task, args=(n, name)) t.start() threads.append(t) @@ -76,27 +76,27 @@ def task(n: int, name: str) -> None: flush() -@pytest.mark.parametrize('niterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) -@pytest.mark.parametrize('nthreads', [3, 1, 0]) +@pytest.mark.parametrize('n_iterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) +@pytest.mark.parametrize('n_threads', [3, 1, 0]) def test_threading( mock_create_presentation: MockCreatePresentation, - nthreads: int, - niterations: list[int], + n_threads: int, + n_iterations: list[int], ) -> None: - # make niterations as long as nthreads. repeat if necessary - niterations = list( + # make n_iterations as long as n_threads. repeat if necessary + n_iterations = list( itertools.chain( - *itertools.repeat(niterations, nthreads // len(niterations) + 1) + *itertools.repeat(n_iterations, n_threads // len(n_iterations) + 1) ) - )[:nthreads] + )[:n_threads] - run_with_threading(nthreads, niterations) + run_with_threading(n_threads, n_iterations) - nreports_expected = sum(niterations) + nthreads + n_reports_expected = sum(n_iterations) + n_threads presentations = mock_create_presentation.presentations - if nreports_expected == 0: + if n_reports_expected == 0: assert 1 == len(presentations) # created by flush() assert 0 == len(presentations[0].reports) return @@ -104,19 +104,19 @@ def test_threading( assert 2 == len(presentations) progressbar0 = presentations[0] - assert nreports_expected == len(progressbar0.reports) - assert nthreads == len(progressbar0.task_ids) - assert nthreads == progressbar0.n_firsts - assert nthreads == progressbar0.n_lasts + assert n_reports_expected == len(progressbar0.reports) + assert n_threads == len(progressbar0.task_ids) + assert n_threads == progressbar0.n_firsts + assert n_threads == progressbar0.n_lasts progressbar1 = presentations[1] assert 0 == len(progressbar1.reports) def run_with_multiprocessing( - nprocesses: int, - ntasks: int, - niterations: list[int], + n_processes: int, + n_tasks: int, + n_iterations: list[int], ) -> None: def task(n: int, name: str) -> None: for i in atpbar(range(n), name=name): @@ -138,47 +138,49 @@ def worker( reporter = find_reporter() queue = multiprocessing.JoinableQueue() # type: ignore - for i in range(nprocesses): + for i in range(n_processes): p = multiprocessing.Process(target=worker, args=(reporter, task, queue)) p.start() - for i in range(ntasks): + for i in range(n_tasks): name = 'task {}'.format(i) - n = niterations[i] + n = n_iterations[i] queue.put((n, name)) - for i in range(nprocesses): + for i in range(n_processes): queue.put(None) queue.join() flush() @pytest.mark.xfail() -@pytest.mark.parametrize('niterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) -@pytest.mark.parametrize('ntasks', [6, 3, 1, 0]) -@pytest.mark.parametrize('nprocesses', [10, 6, 2, 1]) +@pytest.mark.parametrize('n_iterations', [[5, 4, 3], [5, 0, 1], [0], [1]]) +@pytest.mark.parametrize('n_tasks', [6, 3, 1, 0]) +@pytest.mark.parametrize('n_processes', [10, 6, 2, 1]) def test_multiprocessing( mock_create_presentation: MockCreatePresentation, - nprocesses: int, - ntasks: int, - niterations: list[int], + n_processes: int, + n_tasks: int, + n_iterations: list[int], ) -> None: - # make niterations as long as ntasks. repeat if necessary - niterations = list( - itertools.chain(*itertools.repeat(niterations, ntasks // len(niterations) + 1)) - )[:ntasks] + # make n_iterations as long as n_tasks. repeat if necessary + n_iterations = list( + itertools.chain( + *itertools.repeat(n_iterations, n_tasks // len(n_iterations) + 1) + ) + )[:n_tasks] - run_with_multiprocessing(nprocesses, ntasks, niterations) + run_with_multiprocessing(n_processes, n_tasks, n_iterations) - nreports_expected = sum(niterations) + ntasks + n_reports_expected = sum(n_iterations) + n_tasks presentations = mock_create_presentation.presentations assert 2 == len(presentations) # created by find_reporter() and flush() progressbar0 = presentations[0] - assert nreports_expected == len(progressbar0.reports) - assert ntasks == len(progressbar0.task_ids) - assert ntasks == progressbar0.n_firsts - assert ntasks == progressbar0.n_lasts + assert n_reports_expected == len(progressbar0.reports) + assert n_tasks == len(progressbar0.task_ids) + assert n_tasks == progressbar0.n_firsts + assert n_tasks == progressbar0.n_lasts progressbar1 = presentations[1] assert 0 == len(progressbar1.reports) From 0e34ea0aa5f96425979ebda4ee162974c28ad18b Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Mon, 27 May 2024 10:31:14 -0400 Subject: [PATCH 2/4] Update cSpell.words --- .vscode/settings.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index eae31c5..40fa752 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,6 +29,7 @@ ], "cSpell.words": [ "autouse", + "caplog", "capsys", "funcs", "initargs", @@ -38,6 +39,7 @@ "pbar", "pygments", "randint", + "spyder", "starmap", "superfences", "taskid" From a10a785de8d35f30c43d1aa7f029c5aa1f1739f2 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Mon, 27 May 2024 10:42:57 -0400 Subject: [PATCH 3/4] Fix spell checker errors --- atpbar/machine.py | 4 ++-- atpbar/progress_report/reporter.py | 2 +- tests/presentation/test_create_presentation.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/atpbar/machine.py b/atpbar/machine.py index 8fd7e3a..e3036ec 100644 --- a/atpbar/machine.py +++ b/atpbar/machine.py @@ -103,7 +103,7 @@ def __init__(self) -> None: self._start_pickup() if self.stream_redirection.disabled: - self.reporter.stream_redirection_enablaed = False + self.reporter.stream_redirection_enabled = False def _start_pickup(self) -> None: presentation = create_presentation() @@ -176,7 +176,7 @@ def __init__(self, reporter: ProgressReporter | None) -> None: self.reporter = reporter if reporter is None: return - if reporter.stream_redirection_enablaed: + if reporter.stream_redirection_enabled: register_stream_queue(reporter.stream_queue) def fetch_reporter(self, lock: Lock) -> Iterator[ProgressReporter | None]: diff --git a/atpbar/progress_report/reporter.py b/atpbar/progress_report/reporter.py index c041abc..588d8c2 100755 --- a/atpbar/progress_report/reporter.py +++ b/atpbar/progress_report/reporter.py @@ -57,7 +57,7 @@ def __init__( self.complete_report = ProgressReportComplementer() self.notices_from_sub_processes = notices_from_sub_processes self.stream_queue = stream_queue - self.stream_redirection_enablaed = True + self.stream_redirection_enabled = True def __repr__(self) -> str: return '{}(queue={!r}, interval={!r})'.format( diff --git a/tests/presentation/test_create_presentation.py b/tests/presentation/test_create_presentation.py index f9b713a..f8e4547 100644 --- a/tests/presentation/test_create_presentation.py +++ b/tests/presentation/test_create_presentation.py @@ -29,12 +29,12 @@ def isatty(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch) -> b if has_jupyter_notebook: - is_jupyter_notebook_parames = [True, False] + is_jupyter_notebook_params = [True, False] else: - is_jupyter_notebook_parames = [False] + is_jupyter_notebook_params = [False] -@pytest.fixture(params=is_jupyter_notebook_parames) +@pytest.fixture(params=is_jupyter_notebook_params) def is_jupyter_notebook( request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch ) -> bool: From 20216d874864a3426531216b721a37abd801c518 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Mon, 27 May 2024 10:43:19 -0400 Subject: [PATCH 4/4] Update cSpell.words --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 40fa752..8befd37 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -31,14 +31,17 @@ "autouse", "caplog", "capsys", + "delenv", "funcs", "initargs", "inlinehilite", "ipywidgets", + "levelname", "linenums", "pbar", "pygments", "randint", + "setenv", "spyder", "starmap", "superfences",