From 6d8b67666e8a0bfcc380d82dad8f7b8788273de1 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sat, 25 May 2024 09:49:56 -0400 Subject: [PATCH 01/11] Update cSpell.words --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 64df35d..83a571e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,6 +29,7 @@ ], "cSpell.words": [ "autouse", + "capsys", "funcs", "initargs", "inlinehilite", From faceb4ce20b30ec12ee67e15284e96f7cdf51bc2 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sat, 25 May 2024 09:50:07 -0400 Subject: [PATCH 02/11] Fix a typo --- tests/presentation/test_presentation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/presentation/test_presentation.py b/tests/presentation/test_presentation.py index c3b1b74..cebd5a6 100644 --- a/tests/presentation/test_presentation.py +++ b/tests/presentation/test_presentation.py @@ -24,10 +24,10 @@ if has_jupyter_notebook: classes.append(ProgressBarJupyter) -classe_ids = [c.__name__ for c in classes] +class_ids = [c.__name__ for c in classes] -@pytest.mark.parametrize("Class", classes, ids=classe_ids) +@pytest.mark.parametrize("Class", classes, ids=class_ids) def test_presentation(Class: type[Presentation]) -> None: i = uuid.uuid4() j = uuid.uuid4() @@ -49,7 +49,7 @@ def test_presentation(Class: type[Presentation]) -> None: obj.active() -@pytest.mark.parametrize("Class", classes, ids=classe_ids) +@pytest.mark.parametrize("Class", classes, ids=class_ids) def test_time_track(Class: type[Presentation]) -> None: i = uuid.uuid4() obj = Class() From fef738418b0def41a3608fecdac0967ef21b0d88 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sat, 25 May 2024 10:05:16 -0400 Subject: [PATCH 03/11] Add an arg to _present() for better inheritance --- atpbar/presentation/barjupyter.py | 2 +- atpbar/presentation/bartty.py | 2 +- atpbar/presentation/base.py | 4 ++-- atpbar/presentation/txtprint.py | 7 ++----- tests/presentation/test_base.py | 3 ++- tests/scenarios/conftest.py | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/atpbar/presentation/barjupyter.py b/atpbar/presentation/barjupyter.py index 76fe363..9f02b2e 100755 --- a/atpbar/presentation/barjupyter.py +++ b/atpbar/presentation/barjupyter.py @@ -21,7 +21,7 @@ def __init__(self) -> None: def __repr__(self) -> str: return "{}()".format(self.__class__.__name__) - def _present(self) -> None: + def _present(self, report: Report) -> None: self._create_widgets() self._update_widgets() diff --git a/atpbar/presentation/bartty.py b/atpbar/presentation/bartty.py index 5c1ebe9..72e8dd1 100755 --- a/atpbar/presentation/bartty.py +++ b/atpbar/presentation/bartty.py @@ -28,7 +28,7 @@ def _get_width(self) -> int: except AttributeError: return MINIMUM_TERMINAL_WIDTH - def _present(self) -> None: + def _present(self, report: Report) -> None: self._erase_active_bars() self._compose_just_finished_bars() self._compose_active_bars() diff --git a/atpbar/presentation/base.py b/atpbar/presentation/base.py index b83b8fa..dc75460 100755 --- a/atpbar/presentation/base.py +++ b/atpbar/presentation/base.py @@ -43,12 +43,12 @@ def present(self, report: Report) -> None: return if not self._need_to_present(): return - self._present() + self._present(report) self._update_registry() self.last_time = time.time() @abstractmethod - def _present(self) -> None: + def _present(self, report: Report) -> None: pass def _register_report(self, report: Report) -> bool: diff --git a/atpbar/presentation/txtprint.py b/atpbar/presentation/txtprint.py index 1dd4bb2..998d60d 100755 --- a/atpbar/presentation/txtprint.py +++ b/atpbar/presentation/txtprint.py @@ -21,14 +21,11 @@ def present(self, report: Report) -> None: if not self._need_to_present_(report): return - self._present_(report) + self._present(report) self.last_time_map[report["taskid"]] = self._time() - - def _present(self) -> None: - pass - def _present_(self, report: Report) -> None: + def _present(self, report: Report) -> None: time_ = time.strftime("%m/%d %H:%M", time.localtime(time.time())) percent = float(report["done"]) / report["total"] if report["total"] > 0 else 1 percent = round(percent * 100, 2) diff --git a/tests/presentation/test_base.py b/tests/presentation/test_base.py index 7a86119..6af5f2d 100644 --- a/tests/presentation/test_base.py +++ b/tests/presentation/test_base.py @@ -5,10 +5,11 @@ import pytest from atpbar.presentation.base import Presentation +from atpbar.progress_report import Report class MockProgressBar(Presentation): - def _present(self) -> None: + def _present(self, report: Report) -> None: pass diff --git a/tests/scenarios/conftest.py b/tests/scenarios/conftest.py index fb89c8f..969a760 100644 --- a/tests/scenarios/conftest.py +++ b/tests/scenarios/conftest.py @@ -37,7 +37,7 @@ def present(self, report: Report) -> None: self.nfirsts += report["first"] self.nlasts += report["last"] - def _present(self) -> None: + def _present(self, report: Report) -> None: pass From a66854dd0a4e0f7aeb2142893b71849d5d4d953d Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sat, 25 May 2024 10:44:11 -0400 Subject: [PATCH 04/11] Rename _*_taskids to _*_task_ids --- atpbar/presentation/barjupyter.py | 8 +-- atpbar/presentation/bartty.py | 6 +-- atpbar/presentation/base.py | 38 +++++++------- tests/presentation/test_base.py | 84 +++++++++++++++---------------- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/atpbar/presentation/barjupyter.py b/atpbar/presentation/barjupyter.py index 9f02b2e..f84373f 100755 --- a/atpbar/presentation/barjupyter.py +++ b/atpbar/presentation/barjupyter.py @@ -30,7 +30,7 @@ def _create_widgets(self) -> None: self.container_widget = widgets.VBox() display(self.container_widget) - for taskid in self._new_taskids: + for taskid in self._new_task_ids: report = self._report_dict[taskid] self._create_widget(report) @@ -54,14 +54,14 @@ def _create_widget(self, report: Report) -> None: def _update_widgets(self) -> None: for taskid in ( - self._finishing_taskids + self._active_taskids + self._new_taskids + self._finishing_task_ids + self._active_task_ids + self._new_task_ids ): report = self._report_dict[taskid] self._update_widget(report) self._reorder_widgets(report) - if not self._new_taskids and not self._active_taskids: + if not self._new_task_ids and not self._active_task_ids: self.container_widget = None self.active_box_list[:] = [] self.complete_box_list[:] = [] @@ -93,7 +93,7 @@ def _update_widget(self, report: Report) -> None: ) def _reorder_widgets(self, report: Report) -> None: - for taskid in self._finishing_taskids: + for taskid in self._finishing_task_ids: box, bar, label = self.widget_dict[taskid] if box in self.active_box_list: self.active_box_list.remove(box) diff --git a/atpbar/presentation/bartty.py b/atpbar/presentation/bartty.py index 72e8dd1..472e2f3 100755 --- a/atpbar/presentation/bartty.py +++ b/atpbar/presentation/bartty.py @@ -45,7 +45,7 @@ def _write(self, s: str, out: TextIO) -> None: self._draw_active_bars() def _erase_active_bars(self) -> None: - nlines = len(self._active_taskids) + len(self._finishing_taskids) + nlines = len(self._active_task_ids) + len(self._finishing_task_ids) # must be the same as len(self.active_bars) if nlines == 0: @@ -61,13 +61,13 @@ def _erase_active_bars(self) -> None: def _compose_just_finished_bars(self) -> None: self.just_finished_bars = [ - self._compose_bar_from_taskid(i) for i in self._finishing_taskids + self._compose_bar_from_taskid(i) for i in self._finishing_task_ids ] def _compose_active_bars(self) -> None: self.active_bars = [ self._compose_bar_from_taskid(i) - for i in self._active_taskids + self._new_taskids + for i in self._active_task_ids + self._new_task_ids ] def _compose_bar_from_taskid(self, taskid: UUID) -> str: diff --git a/atpbar/presentation/base.py b/atpbar/presentation/base.py index dc75460..fbec71b 100755 --- a/atpbar/presentation/base.py +++ b/atpbar/presentation/base.py @@ -23,17 +23,17 @@ def __init__(self) -> None: self.lock = threading.Lock() - self._new_taskids = list[UUID]() - self._active_taskids = list[UUID]() # in order of arrival - self._finishing_taskids = list[UUID]() - self._complete_taskids = list[UUID]() # in order of completion + self._new_task_ids = list[UUID]() + self._active_task_ids = list[UUID]() # in order of arrival + self._finishing_task_ids = list[UUID]() + self._complete_task_ids = list[UUID]() # in order of completion self._report_dict = dict[UUID, Report]() self.interval = 1.0 # [second] self.last_time = time.time() def active(self) -> bool: - if self._active_taskids: + if self._active_task_ids: return True return False @@ -55,51 +55,51 @@ def _register_report(self, report: Report) -> bool: taskid = report["taskid"] - if taskid in self._complete_taskids: + if taskid in self._complete_task_ids: return False self._report_dict[taskid] = report - if taskid in self._finishing_taskids: + if taskid in self._finishing_task_ids: return True if report["last"]: try: - self._active_taskids.remove(taskid) + self._active_task_ids.remove(taskid) except ValueError: pass try: - self._new_taskids.remove(taskid) + self._new_task_ids.remove(taskid) except ValueError: pass - self._finishing_taskids.append(taskid) + self._finishing_task_ids.append(taskid) return True - if taskid in self._active_taskids: + if taskid in self._active_task_ids: return True - if taskid in self._new_taskids: + if taskid in self._new_task_ids: return True - self._new_taskids.append(taskid) + self._new_task_ids.append(taskid) return True def _update_registry(self) -> None: - self._active_taskids.extend(self._new_taskids) - del self._new_taskids[:] + self._active_task_ids.extend(self._new_task_ids) + del self._new_task_ids[:] - self._complete_taskids.extend(self._finishing_taskids) - del self._finishing_taskids[:] + self._complete_task_ids.extend(self._finishing_task_ids) + del self._finishing_task_ids[:] def _need_to_present(self) -> bool: - if self._new_taskids: + if self._new_task_ids: return True - if self._finishing_taskids: + if self._finishing_task_ids: return True if time.time() - self.last_time > self.interval: diff --git a/tests/presentation/test_base.py b/tests/presentation/test_base.py index 6af5f2d..b9c85fc 100644 --- a/tests/presentation/test_base.py +++ b/tests/presentation/test_base.py @@ -64,10 +64,10 @@ def test_present(obj: Presentation) -> None: ] param_names = ( "report, " - "initial_new_taskids, initial_active_taskids, " - "initial_finishing_taskids, initial_complete_taskids, " - "expected_new_taskids, expected_active_taskids, " - "expected_finishing_taskids, expected_complete_taskids, " + "initial_new_task_ids, initial_active_task_ids, " + "initial_finishing_task_ids, initial_complete_task_ids, " + "expected_new_task_ids, expected_active_task_ids, " + "expected_finishing_task_ids, expected_complete_task_ids, " "expected_return" ) @@ -76,28 +76,28 @@ def test_present(obj: Presentation) -> None: def test_register_report( # type: ignore obj, report, - initial_new_taskids, - initial_active_taskids, - initial_finishing_taskids, - initial_complete_taskids, - expected_new_taskids, - expected_active_taskids, - expected_finishing_taskids, - expected_complete_taskids, + initial_new_task_ids, + initial_active_task_ids, + initial_finishing_task_ids, + initial_complete_task_ids, + expected_new_task_ids, + expected_active_task_ids, + expected_finishing_task_ids, + expected_complete_task_ids, expected_return, ): - obj._new_taskids[:] = initial_new_taskids - obj._active_taskids[:] = initial_active_taskids - obj._finishing_taskids[:] = initial_finishing_taskids - obj._complete_taskids[:] = initial_complete_taskids + obj._new_task_ids[:] = initial_new_task_ids + obj._active_task_ids[:] = initial_active_task_ids + obj._finishing_task_ids[:] = initial_finishing_task_ids + obj._complete_task_ids[:] = initial_complete_task_ids assert expected_return == obj._register_report(report) - assert expected_new_taskids == obj._new_taskids - assert expected_active_taskids == obj._active_taskids - assert expected_finishing_taskids == obj._finishing_taskids - assert expected_complete_taskids == obj._complete_taskids + assert expected_new_task_ids == obj._new_task_ids + assert expected_active_task_ids == obj._active_task_ids + assert expected_finishing_task_ids == obj._finishing_task_ids + assert expected_complete_task_ids == obj._complete_task_ids params = [ @@ -133,37 +133,37 @@ def test_register_report( # type: ignore ), ] param_names = ( - "initial_new_taskids, initial_active_taskids, " - "initial_finishing_taskids, initial_complete_taskids, " - "expected_new_taskids, expected_active_taskids, " - "expected_finishing_taskids, expected_complete_taskids, " + "initial_new_task_ids, initial_active_task_ids, " + "initial_finishing_task_ids, initial_complete_task_ids, " + "expected_new_task_ids, expected_active_task_ids, " + "expected_finishing_task_ids, expected_complete_task_ids, " ) @pytest.mark.parametrize(param_names, params) def test_update_registry( # type: ignore obj, - initial_new_taskids, - initial_active_taskids, - initial_finishing_taskids, - initial_complete_taskids, - expected_new_taskids, - expected_active_taskids, - expected_finishing_taskids, - expected_complete_taskids, + initial_new_task_ids, + initial_active_task_ids, + initial_finishing_task_ids, + initial_complete_task_ids, + expected_new_task_ids, + expected_active_task_ids, + expected_finishing_task_ids, + expected_complete_task_ids, ): - obj._new_taskids[:] = initial_new_taskids - obj._active_taskids[:] = initial_active_taskids - obj._finishing_taskids[:] = initial_finishing_taskids - obj._complete_taskids[:] = initial_complete_taskids + obj._new_task_ids[:] = initial_new_task_ids + obj._active_task_ids[:] = initial_active_task_ids + obj._finishing_task_ids[:] = initial_finishing_task_ids + obj._complete_task_ids[:] = initial_complete_task_ids obj._update_registry() - assert expected_new_taskids == obj._new_taskids - assert expected_active_taskids == obj._active_taskids - assert expected_finishing_taskids == obj._finishing_taskids - assert expected_complete_taskids == obj._complete_taskids + assert expected_new_task_ids == obj._new_task_ids + assert expected_active_task_ids == obj._active_task_ids + assert expected_finishing_task_ids == obj._finishing_task_ids + assert expected_complete_task_ids == obj._complete_task_ids params = [ @@ -189,8 +189,8 @@ def test_need_to_present( # type: ignore expected, ): - obj._new_taskids[:] = new_taskids - obj._finishing_taskids[:] = finishing_taskids + obj._new_task_ids[:] = new_taskids + obj._finishing_task_ids[:] = finishing_taskids mock_time.time.return_value = current_time obj.last_time = last_time From cf2fbdfdc017e2cf86bd3fa2d447d02b855f99cd Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 26 May 2024 09:31:55 -0400 Subject: [PATCH 05/11] Fix pylance error --- atpbar/presentation/barjupyter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/atpbar/presentation/barjupyter.py b/atpbar/presentation/barjupyter.py index f84373f..247108c 100755 --- a/atpbar/presentation/barjupyter.py +++ b/atpbar/presentation/barjupyter.py @@ -74,6 +74,7 @@ def _update_widget(self, report: Report) -> None: percent_fmt = "{:6.2f}%".format(percent) box = self.widget_dict[report["taskid"]][0] + box # to silence not-used warning bar = self.widget_dict[report["taskid"]][1] bar.value = report["done"] From 6e3bffd3d4ba743c2efa4525fd91ff5a8fcc0b48 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 26 May 2024 09:35:23 -0400 Subject: [PATCH 06/11] Rename nlines to n_lines --- atpbar/presentation/bartty.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atpbar/presentation/bartty.py b/atpbar/presentation/bartty.py index 472e2f3..4febecb 100755 --- a/atpbar/presentation/bartty.py +++ b/atpbar/presentation/bartty.py @@ -45,13 +45,13 @@ def _write(self, s: str, out: TextIO) -> None: self._draw_active_bars() def _erase_active_bars(self) -> None: - nlines = len(self._active_task_ids) + len(self._finishing_task_ids) + n_lines = len(self._active_task_ids) + len(self._finishing_task_ids) # must be the same as len(self.active_bars) - if nlines == 0: + if n_lines == 0: return - code = "\033[1G" + "\033[A" * (nlines - 1) + "\033[0J" + code = "\033[1G" + "\033[A" * (n_lines - 1) + "\033[0J" # '\033[1G' move the cursor to the beginning of the line # '\033[A' move the cursor up # '\033[0J' clear from cursor to end of screen From dd096687cde6006e1016a6e9253ed1b7a7cf7ef6 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 26 May 2024 09:41:00 -0400 Subject: [PATCH 07/11] Rename taskids to task_ids --- tests/presentation/test_base.py | 10 +++++----- tests/scenarios/conftest.py | 8 ++++---- tests/scenarios/test_last_report.py | 2 +- tests/scenarios/test_multiprocessing.py | 8 ++++---- tests/scenarios/test_readme_quick_start.py | 8 ++++---- tests/scenarios/test_threading.py | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/presentation/test_base.py b/tests/presentation/test_base.py index b9c85fc..69b95a6 100644 --- a/tests/presentation/test_base.py +++ b/tests/presentation/test_base.py @@ -173,7 +173,7 @@ def test_update_registry( # type: ignore pytest.param([], [], 4.0, 2.0, 3.0, False), ] param_names = ( - "new_taskids, finishing_taskids, " "current_time, last_time, interval, expected" + "new_task_ids, finishing_task_ids, " "current_time, last_time, interval, expected" ) @@ -181,16 +181,16 @@ def test_update_registry( # type: ignore def test_need_to_present( # type: ignore obj, mock_time, - new_taskids, - finishing_taskids, + new_task_ids, + finishing_task_ids, current_time, last_time, interval, expected, ): - obj._new_task_ids[:] = new_taskids - obj._finishing_task_ids[:] = finishing_taskids + obj._new_task_ids[:] = new_task_ids + obj._finishing_task_ids[:] = finishing_task_ids mock_time.time.return_value = current_time obj.last_time = last_time diff --git a/tests/scenarios/conftest.py b/tests/scenarios/conftest.py index 969a760..97877b0 100644 --- a/tests/scenarios/conftest.py +++ b/tests/scenarios/conftest.py @@ -13,16 +13,16 @@ class MockProgressBar(Presentation): def __init__(self) -> None: super().__init__() self.reports = list[Report]() - self.taskids = set[UUID]() + self.task_ids = set[UUID]() self.nfirsts = 0 self.nlasts = 0 def __str__(self) -> str: lines = [] - l = "{}: # reports: {}, # taskids: {}, # firsts: {}, # lasts: {}".format( + l = "{}: # reports: {}, # task_ids: {}, # firsts: {}, # lasts: {}".format( self.__class__.__name__, len(self.reports), - len(self.taskids), + len(self.task_ids), self.nfirsts, self.nlasts, ) @@ -33,7 +33,7 @@ def __str__(self) -> str: def present(self, report: Report) -> None: super().present(report) self.reports.append(report) - self.taskids.add(report["taskid"]) + self.task_ids.add(report["taskid"]) self.nfirsts += report["first"] self.nlasts += report["last"] diff --git a/tests/scenarios/test_last_report.py b/tests/scenarios/test_last_report.py index 77b6370..7966512 100644 --- a/tests/scenarios/test_last_report.py +++ b/tests/scenarios/test_last_report.py @@ -50,7 +50,7 @@ def task_exception(ndones: int, niterations: int) -> None: # progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) - assert 1 == len(progressbar0.taskids) + assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.nfirsts assert 1 == progressbar0.nlasts done_total_list_expected = [(ndones, niterations)] diff --git a/tests/scenarios/test_multiprocessing.py b/tests/scenarios/test_multiprocessing.py index e378fc8..4c0e404 100644 --- a/tests/scenarios/test_multiprocessing.py +++ b/tests/scenarios/test_multiprocessing.py @@ -94,7 +94,7 @@ def test_multiprocessing_from_loop( assert 1 == progressbar0.nfirsts assert 1 == progressbar0.nlasts - assert 1 == len(progressbar0.taskids) + assert 1 == len(progressbar0.task_ids) else: if 2 == len(presentations): @@ -103,7 +103,7 @@ def test_multiprocessing_from_loop( assert 0 == len(progressbar1.reports) progressbar0 = presentations[0] - assert ntasks + 1 == len(progressbar0.taskids) + assert ntasks + 1 == len(progressbar0.task_ids) assert ntasks + 1 == progressbar0.nfirsts assert ntasks + 1 == progressbar0.nlasts assert nreports_expected == len(progressbar0.reports) @@ -117,7 +117,7 @@ def test_multiprocessing_from_loop( progressbar0 = presentations[0] progressbar1 = presentations[1] - assert ntasks + 1 == len(progressbar0.taskids) + len(progressbar1.taskids) + assert ntasks + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) assert ntasks + 1 == progressbar0.nfirsts + progressbar1.nfirsts assert ntasks + 1 == progressbar0.nlasts + progressbar1.nlasts assert nreports_expected == len(progressbar0.reports) + len( @@ -131,7 +131,7 @@ def test_multiprocessing_from_loop( pass assert npresentations + 1 == len(presentations) progressbar = presentations[-2] - assert 1 == len(progressbar.taskids) + assert 1 == len(progressbar.task_ids) assert 1 == progressbar.nfirsts assert 1 == progressbar.nlasts assert 4 + 1 == len(progressbar.reports) diff --git a/tests/scenarios/test_readme_quick_start.py b/tests/scenarios/test_readme_quick_start.py index 88b5038..0232e7d 100644 --- a/tests/scenarios/test_readme_quick_start.py +++ b/tests/scenarios/test_readme_quick_start.py @@ -31,7 +31,7 @@ def test_one_loop( # progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) - assert 1 == len(progressbar0.taskids) + assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.nfirsts assert 1 == progressbar0.nlasts @@ -51,7 +51,7 @@ def test_nested_loops(mock_create_presentation: MockCreatePresentation) -> None: progressbar0 = presentations[0] assert (3 + 1) * 4 + 4 + 1 == len(progressbar0.reports) - assert 5 == len(progressbar0.taskids) + assert 5 == len(progressbar0.task_ids) assert 5 == progressbar0.nfirsts assert 5 == progressbar0.nlasts @@ -105,7 +105,7 @@ def test_threading( progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) - assert nthreads == len(progressbar0.taskids) + assert nthreads == len(progressbar0.task_ids) assert nthreads == progressbar0.nfirsts assert nthreads == progressbar0.nlasts @@ -176,7 +176,7 @@ def test_multiprocessing( progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) - assert ntasks == len(progressbar0.taskids) + assert ntasks == len(progressbar0.task_ids) assert ntasks == progressbar0.nfirsts assert ntasks == progressbar0.nlasts diff --git a/tests/scenarios/test_threading.py b/tests/scenarios/test_threading.py index b62ce4b..51622cf 100644 --- a/tests/scenarios/test_threading.py +++ b/tests/scenarios/test_threading.py @@ -88,7 +88,7 @@ def task( assert nreports_expected == len(progressbar0.reports) # one report from `atpbar` in the main thread - assert 1 == len(progressbar0.taskids) + assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.nfirsts assert 1 == progressbar0.nlasts @@ -98,7 +98,7 @@ def task( progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) - assert nthreads + 1 == len(progressbar0.taskids) + assert nthreads + 1 == len(progressbar0.task_ids) assert nthreads + 1 == progressbar0.nfirsts assert nthreads + 1 == progressbar0.nlasts @@ -114,7 +114,7 @@ def task( assert nreports_expected == len(progressbar0.reports) + len( progressbar1.reports ) - assert nthreads + 1 == len(progressbar0.taskids) + len(progressbar1.taskids) + assert nthreads + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) assert nthreads + 1 == progressbar0.nfirsts + progressbar1.nfirsts assert nthreads + 1 == progressbar0.nlasts + progressbar1.nlasts @@ -129,6 +129,6 @@ def task( assert npresentations + 1 == len(presentations) progressbar = presentations[-2] assert 4 + 1 == len(progressbar.reports) - assert 1 == len(progressbar.taskids) + assert 1 == len(progressbar.task_ids) assert 1 == progressbar.nfirsts assert 1 == progressbar.nlasts From 8ddd11ce6ef0f09262990d799b8209c209b79595 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 26 May 2024 09:44:47 -0400 Subject: [PATCH 08/11] Rename nfirsts to n_firsts --- tests/scenarios/conftest.py | 6 +++--- tests/scenarios/test_last_report.py | 2 +- tests/scenarios/test_multiprocessing.py | 8 ++++---- tests/scenarios/test_readme_quick_start.py | 8 ++++---- tests/scenarios/test_threading.py | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/scenarios/conftest.py b/tests/scenarios/conftest.py index 97877b0..470a50a 100644 --- a/tests/scenarios/conftest.py +++ b/tests/scenarios/conftest.py @@ -14,7 +14,7 @@ def __init__(self) -> None: super().__init__() self.reports = list[Report]() self.task_ids = set[UUID]() - self.nfirsts = 0 + self.n_firsts = 0 self.nlasts = 0 def __str__(self) -> str: @@ -23,7 +23,7 @@ def __str__(self) -> str: self.__class__.__name__, len(self.reports), len(self.task_ids), - self.nfirsts, + self.n_firsts, self.nlasts, ) lines.append(l) @@ -34,7 +34,7 @@ def present(self, report: Report) -> None: super().present(report) self.reports.append(report) self.task_ids.add(report["taskid"]) - self.nfirsts += report["first"] + self.n_firsts += report["first"] self.nlasts += report["last"] def _present(self, report: Report) -> None: diff --git a/tests/scenarios/test_last_report.py b/tests/scenarios/test_last_report.py index 7966512..df441ec 100644 --- a/tests/scenarios/test_last_report.py +++ b/tests/scenarios/test_last_report.py @@ -51,7 +51,7 @@ def task_exception(ndones: int, niterations: int) -> None: progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) assert 1 == len(progressbar0.task_ids) - assert 1 == progressbar0.nfirsts + assert 1 == progressbar0.n_firsts assert 1 == progressbar0.nlasts done_total_list_expected = [(ndones, niterations)] done_total_list_actual = [ diff --git a/tests/scenarios/test_multiprocessing.py b/tests/scenarios/test_multiprocessing.py index 4c0e404..17fa5f0 100644 --- a/tests/scenarios/test_multiprocessing.py +++ b/tests/scenarios/test_multiprocessing.py @@ -92,7 +92,7 @@ def test_multiprocessing_from_loop( assert nreports_expected == len(progressbar0.reports) # one report from `atpbar` in the main thread - assert 1 == progressbar0.nfirsts + assert 1 == progressbar0.n_firsts assert 1 == progressbar0.nlasts assert 1 == len(progressbar0.task_ids) @@ -104,7 +104,7 @@ def test_multiprocessing_from_loop( progressbar0 = presentations[0] assert ntasks + 1 == len(progressbar0.task_ids) - assert ntasks + 1 == progressbar0.nfirsts + assert ntasks + 1 == progressbar0.n_firsts assert ntasks + 1 == progressbar0.nlasts assert nreports_expected == len(progressbar0.reports) @@ -118,7 +118,7 @@ def test_multiprocessing_from_loop( progressbar1 = presentations[1] assert ntasks + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) - assert ntasks + 1 == progressbar0.nfirsts + progressbar1.nfirsts + assert ntasks + 1 == progressbar0.n_firsts + progressbar1.n_firsts assert ntasks + 1 == progressbar0.nlasts + progressbar1.nlasts assert nreports_expected == len(progressbar0.reports) + len( progressbar1.reports @@ -132,6 +132,6 @@ def test_multiprocessing_from_loop( assert npresentations + 1 == len(presentations) progressbar = presentations[-2] assert 1 == len(progressbar.task_ids) - assert 1 == progressbar.nfirsts + assert 1 == progressbar.n_firsts assert 1 == progressbar.nlasts assert 4 + 1 == len(progressbar.reports) diff --git a/tests/scenarios/test_readme_quick_start.py b/tests/scenarios/test_readme_quick_start.py index 0232e7d..882850f 100644 --- a/tests/scenarios/test_readme_quick_start.py +++ b/tests/scenarios/test_readme_quick_start.py @@ -32,7 +32,7 @@ def test_one_loop( progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) assert 1 == len(progressbar0.task_ids) - assert 1 == progressbar0.nfirsts + assert 1 == progressbar0.n_firsts assert 1 == progressbar0.nlasts # @@ -52,7 +52,7 @@ def test_nested_loops(mock_create_presentation: MockCreatePresentation) -> None: progressbar0 = presentations[0] assert (3 + 1) * 4 + 4 + 1 == len(progressbar0.reports) assert 5 == len(progressbar0.task_ids) - assert 5 == progressbar0.nfirsts + assert 5 == progressbar0.n_firsts assert 5 == progressbar0.nlasts progressbar1 = presentations[1] @@ -106,7 +106,7 @@ def test_threading( progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) assert nthreads == len(progressbar0.task_ids) - assert nthreads == progressbar0.nfirsts + assert nthreads == progressbar0.n_firsts assert nthreads == progressbar0.nlasts progressbar1 = presentations[1] @@ -177,7 +177,7 @@ def test_multiprocessing( progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) assert ntasks == len(progressbar0.task_ids) - assert ntasks == progressbar0.nfirsts + assert ntasks == progressbar0.n_firsts assert ntasks == progressbar0.nlasts progressbar1 = presentations[1] diff --git a/tests/scenarios/test_threading.py b/tests/scenarios/test_threading.py index 51622cf..0142882 100644 --- a/tests/scenarios/test_threading.py +++ b/tests/scenarios/test_threading.py @@ -89,7 +89,7 @@ def task( # one report from `atpbar` in the main thread assert 1 == len(progressbar0.task_ids) - assert 1 == progressbar0.nfirsts + assert 1 == progressbar0.n_firsts assert 1 == progressbar0.nlasts else: @@ -99,7 +99,7 @@ def task( progressbar0 = presentations[0] assert nreports_expected == len(progressbar0.reports) assert nthreads + 1 == len(progressbar0.task_ids) - assert nthreads + 1 == progressbar0.nfirsts + assert nthreads + 1 == progressbar0.n_firsts assert nthreads + 1 == progressbar0.nlasts progressbar1 = presentations[1] @@ -115,7 +115,7 @@ def task( progressbar1.reports ) assert nthreads + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) - assert nthreads + 1 == progressbar0.nfirsts + progressbar1.nfirsts + assert nthreads + 1 == progressbar0.n_firsts + progressbar1.n_firsts assert nthreads + 1 == progressbar0.nlasts + progressbar1.nlasts progressbar2 = presentations[2] @@ -130,5 +130,5 @@ def task( progressbar = presentations[-2] assert 4 + 1 == len(progressbar.reports) assert 1 == len(progressbar.task_ids) - assert 1 == progressbar.nfirsts + assert 1 == progressbar.n_firsts assert 1 == progressbar.nlasts From 20c498e1404d5cfb3d74bbf673af40982c5a2004 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 26 May 2024 09:46:45 -0400 Subject: [PATCH 09/11] Rename nlasts to n_lasts --- tests/scenarios/conftest.py | 6 +++--- tests/scenarios/test_last_report.py | 2 +- tests/scenarios/test_multiprocessing.py | 8 ++++---- tests/scenarios/test_readme_quick_start.py | 8 ++++---- tests/scenarios/test_threading.py | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/scenarios/conftest.py b/tests/scenarios/conftest.py index 470a50a..69c2b05 100644 --- a/tests/scenarios/conftest.py +++ b/tests/scenarios/conftest.py @@ -15,7 +15,7 @@ def __init__(self) -> None: self.reports = list[Report]() self.task_ids = set[UUID]() self.n_firsts = 0 - self.nlasts = 0 + self.n_lasts = 0 def __str__(self) -> str: lines = [] @@ -24,7 +24,7 @@ def __str__(self) -> str: len(self.reports), len(self.task_ids), self.n_firsts, - self.nlasts, + self.n_lasts, ) lines.append(l) lines.extend([" {}".format(r) for r in self.reports]) @@ -35,7 +35,7 @@ def present(self, report: Report) -> None: self.reports.append(report) self.task_ids.add(report["taskid"]) self.n_firsts += report["first"] - self.nlasts += report["last"] + self.n_lasts += report["last"] def _present(self, report: Report) -> None: pass diff --git a/tests/scenarios/test_last_report.py b/tests/scenarios/test_last_report.py index df441ec..ae1bf04 100644 --- a/tests/scenarios/test_last_report.py +++ b/tests/scenarios/test_last_report.py @@ -52,7 +52,7 @@ def task_exception(ndones: int, niterations: int) -> None: assert nreports_expected == len(progressbar0.reports) assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.n_firsts - assert 1 == progressbar0.nlasts + assert 1 == progressbar0.n_lasts done_total_list_expected = [(ndones, niterations)] 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 17fa5f0..6273659 100644 --- a/tests/scenarios/test_multiprocessing.py +++ b/tests/scenarios/test_multiprocessing.py @@ -93,7 +93,7 @@ def test_multiprocessing_from_loop( # one report from `atpbar` in the main thread assert 1 == progressbar0.n_firsts - assert 1 == progressbar0.nlasts + assert 1 == progressbar0.n_lasts assert 1 == len(progressbar0.task_ids) else: @@ -105,7 +105,7 @@ def test_multiprocessing_from_loop( progressbar0 = presentations[0] assert ntasks + 1 == len(progressbar0.task_ids) assert ntasks + 1 == progressbar0.n_firsts - assert ntasks + 1 == progressbar0.nlasts + assert ntasks + 1 == progressbar0.n_lasts assert nreports_expected == len(progressbar0.reports) else: @@ -119,7 +119,7 @@ def test_multiprocessing_from_loop( assert ntasks + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) assert ntasks + 1 == progressbar0.n_firsts + progressbar1.n_firsts - assert ntasks + 1 == progressbar0.nlasts + progressbar1.nlasts + assert ntasks + 1 == progressbar0.n_lasts + progressbar1.n_lasts assert nreports_expected == len(progressbar0.reports) + len( progressbar1.reports ) @@ -133,5 +133,5 @@ def test_multiprocessing_from_loop( progressbar = presentations[-2] assert 1 == len(progressbar.task_ids) assert 1 == progressbar.n_firsts - assert 1 == progressbar.nlasts + assert 1 == progressbar.n_lasts assert 4 + 1 == len(progressbar.reports) diff --git a/tests/scenarios/test_readme_quick_start.py b/tests/scenarios/test_readme_quick_start.py index 882850f..a854f0c 100644 --- a/tests/scenarios/test_readme_quick_start.py +++ b/tests/scenarios/test_readme_quick_start.py @@ -33,7 +33,7 @@ def test_one_loop( assert nreports_expected == len(progressbar0.reports) assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.n_firsts - assert 1 == progressbar0.nlasts + assert 1 == progressbar0.n_lasts # progressbar1 = presentations[1] @@ -53,7 +53,7 @@ def test_nested_loops(mock_create_presentation: MockCreatePresentation) -> None: assert (3 + 1) * 4 + 4 + 1 == len(progressbar0.reports) assert 5 == len(progressbar0.task_ids) assert 5 == progressbar0.n_firsts - assert 5 == progressbar0.nlasts + assert 5 == progressbar0.n_lasts progressbar1 = presentations[1] assert 0 == len(progressbar1.reports) @@ -107,7 +107,7 @@ def test_threading( assert nreports_expected == len(progressbar0.reports) assert nthreads == len(progressbar0.task_ids) assert nthreads == progressbar0.n_firsts - assert nthreads == progressbar0.nlasts + assert nthreads == progressbar0.n_lasts progressbar1 = presentations[1] assert 0 == len(progressbar1.reports) @@ -178,7 +178,7 @@ def test_multiprocessing( assert nreports_expected == len(progressbar0.reports) assert ntasks == len(progressbar0.task_ids) assert ntasks == progressbar0.n_firsts - assert ntasks == progressbar0.nlasts + assert ntasks == progressbar0.n_lasts progressbar1 = presentations[1] assert 0 == len(progressbar1.reports) diff --git a/tests/scenarios/test_threading.py b/tests/scenarios/test_threading.py index 0142882..2243e53 100644 --- a/tests/scenarios/test_threading.py +++ b/tests/scenarios/test_threading.py @@ -90,7 +90,7 @@ def task( assert 1 == len(progressbar0.task_ids) assert 1 == progressbar0.n_firsts - assert 1 == progressbar0.nlasts + assert 1 == progressbar0.n_lasts else: @@ -100,7 +100,7 @@ def task( assert nreports_expected == len(progressbar0.reports) assert nthreads + 1 == len(progressbar0.task_ids) assert nthreads + 1 == progressbar0.n_firsts - assert nthreads + 1 == progressbar0.nlasts + assert nthreads + 1 == progressbar0.n_lasts progressbar1 = presentations[1] assert 0 == len(progressbar1.reports) @@ -116,7 +116,7 @@ def task( ) assert nthreads + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) assert nthreads + 1 == progressbar0.n_firsts + progressbar1.n_firsts - assert nthreads + 1 == progressbar0.nlasts + progressbar1.nlasts + assert nthreads + 1 == progressbar0.n_lasts + progressbar1.n_lasts progressbar2 = presentations[2] assert 0 == len(progressbar2.reports) @@ -131,4 +131,4 @@ def task( assert 4 + 1 == len(progressbar.reports) assert 1 == len(progressbar.task_ids) assert 1 == progressbar.n_firsts - assert 1 == progressbar.nlasts + assert 1 == progressbar.n_lasts From d65cb542a2f7a17a5875b76a56c40aae4f748101 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 26 May 2024 09:50:44 -0400 Subject: [PATCH 10/11] Rename variables in test_threading.py --- tests/scenarios/test_threading.py | 58 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/tests/scenarios/test_threading.py b/tests/scenarios/test_threading.py index 2243e53..1d60bd2 100644 --- a/tests/scenarios/test_threading.py +++ b/tests/scenarios/test_threading.py @@ -10,25 +10,25 @@ @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("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_from_loop( mock_create_presentation: MockCreatePresentation, - nthreads: int, - niterations: list[int], + n_threads: int, + n_iterations: list[int], time_starting_task: float, ) -> 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] def run_with_threading( - nthreads: int = 3, - niterations: list[int] = [5, 5, 5], + n_threads: int = 3, + n_iterations: list[int] = [5, 5, 5], time_starting_task: float = 0, ) -> None: @@ -50,10 +50,10 @@ def task( # until the progress bar for this loop finish updating. Otherwise, # progress bars from threads are being updated together with the # progress bar for this loop and the `atpbar` will not wait. - for i in atpbar(range(nthreads)): + for i in atpbar(range(n_threads)): name = "thread {}".format(i) - n = niterations[i] + n = n_iterations[i] t = threading.Thread(target=task, args=(n, name, time_starting_task)) t.start() threads.append(t) @@ -68,24 +68,24 @@ def task( flush() - run_with_threading(nthreads, niterations, time_starting_task) + run_with_threading(n_threads, n_iterations, time_starting_task) ## print() ## print(mock_create_presentation) - nreports_expected_from_main = nthreads + 1 - nreports_expected_from_threads = sum(niterations) + nthreads - nreports_expected = nreports_expected_from_main + nreports_expected_from_threads + n_reports_expected_from_main = n_threads + 1 + n_reports_expected_from_threads = sum(n_iterations) + n_threads + n_reports_expected = n_reports_expected_from_main + n_reports_expected_from_threads presentations = mock_create_presentation.presentations - if nreports_expected_from_threads == 0: + if n_reports_expected_from_threads == 0: assert 3 == len(presentations) # when `atpbar` in the main thread # starts and end and when flush() is # called 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 == len(progressbar0.task_ids) @@ -97,10 +97,10 @@ def task( if 2 == len(presentations): progressbar0 = presentations[0] - assert nreports_expected == len(progressbar0.reports) - assert nthreads + 1 == len(progressbar0.task_ids) - assert nthreads + 1 == progressbar0.n_firsts - assert nthreads + 1 == progressbar0.n_lasts + assert n_reports_expected == len(progressbar0.reports) + assert n_threads + 1 == len(progressbar0.task_ids) + assert n_threads + 1 == progressbar0.n_firsts + assert n_threads + 1 == progressbar0.n_lasts progressbar1 = presentations[1] assert 0 == len(progressbar1.reports) @@ -111,22 +111,24 @@ def task( progressbar0 = presentations[0] progressbar1 = presentations[1] - assert nreports_expected == len(progressbar0.reports) + len( + assert n_reports_expected == len(progressbar0.reports) + len( progressbar1.reports ) - assert nthreads + 1 == len(progressbar0.task_ids) + len(progressbar1.task_ids) - assert nthreads + 1 == progressbar0.n_firsts + progressbar1.n_firsts - assert nthreads + 1 == progressbar0.n_lasts + progressbar1.n_lasts + assert n_threads + 1 == len(progressbar0.task_ids) + len( + progressbar1.task_ids + ) + assert n_threads + 1 == progressbar0.n_firsts + progressbar1.n_firsts + assert n_threads + 1 == progressbar0.n_lasts + progressbar1.n_lasts progressbar2 = presentations[2] assert 0 == len(progressbar2.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 4 + 1 == len(progressbar.reports) assert 1 == len(progressbar.task_ids) From 944f098cc1f9757f7bb76605860a61720c568121 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Sun, 26 May 2024 09:51:07 -0400 Subject: [PATCH 11/11] Update cSpell.words --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 83a571e..eae31c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -33,6 +33,7 @@ "funcs", "initargs", "inlinehilite", + "ipywidgets", "linenums", "pbar", "pygments",