Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spell checker errors #48

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@
],
"cSpell.words": [
"autouse",
"caplog",
"capsys",
"delenv",
"funcs",
"initargs",
"inlinehilite",
"ipywidgets",
"levelname",
"linenums",
"pbar",
"pygments",
"randint",
"setenv",
"spyder",
"starmap",
"superfences",
"taskid"
Expand Down
4 changes: 2 additions & 2 deletions atpbar/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion atpbar/progress_report/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/presentation/test_create_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@


if has_jupyter_notebook:
is_jupyter_notebook_parames = [True, False]
is_jupyter_notebook_params = [True, False]

Check warning on line 32 in tests/presentation/test_create_presentation.py

View check run for this annotation

Codecov / codecov/patch

tests/presentation/test_create_presentation.py#L32

Added line #L32 was not covered by tests
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:
Expand Down
64 changes: 33 additions & 31 deletions tests/scenarios/test_disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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)
Expand Down
36 changes: 18 additions & 18 deletions tests/scenarios/test_last_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]
Expand Down
66 changes: 35 additions & 31 deletions tests/scenarios/test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading