Skip to content

Commit 9833f45

Browse files
authored
Merge pull request #3 from viljarjf/bugfix_simulation
Use regex to allow multiple lengths for progress bar
2 parents 23ad558 + e1d71a2 commit 9833f45

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

diffsims/tests/generators/test_simulation_generator.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import numpy as np
2020
import pytest
2121
from pathlib import Path
22+
import re
2223

2324
import diffpy.structure
2425
from orix.crystal_map import Phase
@@ -359,10 +360,9 @@ def test_calculate_diffraction2d_progressbar_single_phase(capsys):
359360
sims = gen.calculate_diffraction2d(phase, rots, show_progressbar=True)
360361

361362
captured = capsys.readouterr()
362-
expected = "test phase: 100%|██████████| 10/10" # also some more, but that is compute-time dependent
363-
# ignore possible flushing
364-
captured = captured.err.split("\r")[-1]
365-
assert "████" in captured # This can be faulty on CI, but we check for the bar
363+
# Accept any number of "█" characters
364+
expected = "test phase: 100\%\|█+\| 10\/10"
365+
assert re.findall(expected, captured.err)
366366

367367

368368
def test_calculate_diffraction2d_progressbar_multi_phase(capsys):
@@ -388,15 +388,8 @@ def test_calculate_diffraction2d_progressbar_multi_phase(capsys):
388388
)
389389

390390
captured = capsys.readouterr()
391-
expected1 = "A: 100%|██████████| 10/10 "
392-
expected2 = "B: 100%|██████████| 10/10 "
393-
# Find the correct output in the stream, i.e. final line containing the name of the phase
394-
captured1 = ""
395-
captured2 = ""
396-
for line in captured.err.split("\r"):
397-
if "A" in line:
398-
captured1 = line
399-
if "B" in line:
400-
captured2 = line
401-
assert "██" in captured1 # This can be faulty on CI
402-
assert "██" in captured2 # Just make sure there is some progress bar
391+
# Accept any number of "█" characters
392+
expected1 = "A: 100\%\|█+\| 10\/10 "
393+
expected2 = "B: 100\%\|█+\| 10\/10 "
394+
assert re.findall(expected1, captured.err)
395+
assert re.findall(expected2, captured.err)

0 commit comments

Comments
 (0)