Skip to content

Commit

Permalink
FIX/add: pytest ordering to avoid concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
p-huynh committed Mar 21, 2024
1 parent 7e1a4b1 commit 34b2c7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/unit/cipher_modules/report_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from claasp.cipher_modules.component_analysis_tests import CipherComponentsAnalysis

import pytest
@pytest.mark.order(-5)
def test_save_as_image():
speck = SpeckBlockCipher(number_of_rounds=2)
sat = SatXorDifferentialModel(speck)
Expand Down Expand Up @@ -49,7 +50,7 @@ def test_save_as_image():
report_cca = Report(component_analysis)
report_cca.save_as_image()


@pytest.mark.order(-4)
def test_save_as_latex_table():
simon = SimonBlockCipher(number_of_rounds=2)
smt = SmtXorDifferentialModel(simon)
Expand Down Expand Up @@ -78,6 +79,7 @@ def test_save_as_latex_table():
report_sts = Report(nist.nist_statistical_tests('avalanche'))
report_sts.save_as_latex_table()

@pytest.mark.order(-3)
def test_save_as_DataFrame():
speck = SpeckBlockCipher(number_of_rounds=2)
cp = CpXorDifferentialModel(speck)
Expand Down Expand Up @@ -105,6 +107,7 @@ def test_save_as_DataFrame():
report_sts.save_as_DataFrame()


@pytest.mark.order(-2)
def test_save_as_json():
simon = SimonBlockCipher(number_of_rounds=2)

Expand Down Expand Up @@ -145,6 +148,7 @@ def test_clean_reports():
blackbox_report.clean_reports()


@pytest.mark.order(-6)
def test_show():
speck = SpeckBlockCipher(number_of_rounds=3)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
REPORT_EXAMPLE_TXT = 'claasp/cipher_modules/statistical_tests/finalAnalysisReportExample.txt'


@pytest.mark.order(1)
def test_run_nist_statistical_tests_tool():
if os.path.exists('test_reports/statistical_tests/experiments'):
os.removedirs('test_reports/statistical_tests/experiments')
Expand All @@ -18,6 +19,7 @@ def test_run_nist_statistical_tests_tool():
assert result is True


@pytest.mark.order(2)
def test_parse_report():
dictio = NISTStatisticalTests._parse_report(REPORT_EXAMPLE_TXT)

Expand All @@ -26,6 +28,7 @@ def test_parse_report():
assert dictio['randomness_test'][0]['passed'] is False


@pytest.mark.order(3)
def test_generate_chart_round():
dictio = NISTStatisticalTests._parse_report(REPORT_EXAMPLE_TXT)
dictio['data_type'] = 'random'
Expand All @@ -44,6 +47,7 @@ def test_generate_chart_round():
'Drawing round 1 is finished.\n'


@pytest.mark.order(4)
def test_generate_chart_all():
dictio = NISTStatisticalTests._parse_report(REPORT_EXAMPLE_TXT)
dictio['data_type'] = 'random'
Expand All @@ -59,6 +63,7 @@ def test_generate_chart_all():
sys.stdout = old_stdout


@pytest.mark.order(5)
def test_run_avalanche_nist_statistics_test():
tests = NISTStatisticalTests(SimonBlockCipher(number_of_rounds=1))
old_stdout = sys.stdout
Expand All @@ -69,6 +74,7 @@ def test_run_avalanche_nist_statistics_test():
return_str = result.getvalue()
assert return_str.find('Finished.') == len(return_str) - 10

@pytest.mark.order(6)
def test_run_correlation_nist_statistics_test():
tests = NISTStatisticalTests(SimonBlockCipher(number_of_rounds=1))
old_stdout = sys.stdout
Expand All @@ -91,6 +97,7 @@ def test_run_CBC_nist_statistics_test():
assert return_str.find('Finished.') == len(return_str) - 10


@pytest.mark.order(7)
def test_run_random_nist_statistics_test():
tests = NISTStatisticalTests(SimonBlockCipher(number_of_rounds=1))
old_stdout = sys.stdout
Expand All @@ -101,6 +108,7 @@ def test_run_random_nist_statistics_test():
return_str = result.getvalue()
assert return_str.find('Finished.') == len(return_str) - 10

@pytest.mark.order(8)
def test_run_low_density_nist_statistics_test():
tests = NISTStatisticalTests(SimonBlockCipher(number_of_rounds=1))
old_stdout = sys.stdout
Expand All @@ -111,6 +119,7 @@ def test_run_low_density_nist_statistics_test():
return_str = result.getvalue()
assert return_str.find('Finished.') == len(return_str) - 10

@pytest.mark.order(9)
def test_run_high_density_nist_statistics_test():
tests = NISTStatisticalTests(SimonBlockCipher(number_of_rounds=1))
old_stdout = sys.stdout
Expand Down

0 comments on commit 34b2c7b

Please sign in to comment.