diff --git a/heman/api/pvcalculator/pvcalculator_test.py b/heman/api/pvcalculator/pvcalculator_test.py index 1e12b75..41c75a4 100644 --- a/heman/api/pvcalculator/pvcalculator_test.py +++ b/heman/api/pvcalculator/pvcalculator_test.py @@ -8,6 +8,10 @@ from ...config import create_app from ...auth import APIUser import os +try: + from pathlib2 import Path +except ImportError: + from pathlib import Path @pytest.fixture def snapshot(request): @@ -26,22 +30,22 @@ def normalize(x): return x def assertion(data, snapshot=None): - snapshotdir = 'testdata/snapshots/' + snapshotdir = Path('testdata/snapshots/') snapshot = snapshot or '.'.join([request.node.module.__name__, request.node.name]) - snapshotfile = snapshotdir + snapshot - resultfile = snapshotfile + '.result' + snapshotfile = snapshotdir / (snapshot+'.expected') + resultfile = snapshotdir / (snapshot+'.result') ns(snapshot=normalize(data)).dump(resultfile) - assert os.path.exists(snapshotfile), ( + assert snapshotfile.exists(), ( "First snapshot, check results and accept them with:\n" - "mv {0}.result {0}".format(snapshotfile) + "mv {} {}".format(resultfile, snapshotfile) ) expected = ns.load(snapshotfile) - assert file(resultfile).read() == file(snapshotfile).read(), ( + assert resultfile.read_text(encoding='utf8') == snapshotfile.read_text('utf8'), ( "Failed snapshot. Check the result and if it is ok accept it with:\n" - "mv {0}.result {0}".format(snapshotfile) + "mv {} {}".format(resultfile, snapshotfile) ) # the result is keept if any of the former asserts fails - os.unlink(resultfile) + resultfile.unlink() return assertion @pytest.fixture diff --git a/testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__optimal_payback b/testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__optimal_payback.expected similarity index 100% rename from testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__optimal_payback rename to testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__optimal_payback.expected diff --git a/testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__with_power b/testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__with_power.expected similarity index 100% rename from testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__with_power rename to testdata/snapshots/heman.api.pvcalculator.pvcalculator_test.test__scenario_report__with_power.expected