1
+ import copy
1
2
import pathlib
2
3
3
4
import pytest
@@ -41,6 +42,7 @@ def test_reload(standard):
41
42
assert isinstance (standard .data , dict )
42
43
assert isinstance (standard .metadata , dict )
43
44
assert isinstance (standard .metadata ["run_info" ], dict )
45
+ assert standard .metadata ["NOTICE" ] == "THIS FILE IS ONLY USED IN UNIT TESTS. THE NUMBERS ARE FAKE."
44
46
45
47
46
48
def test_append_run_info (standard , extra1 , extra2 ):
@@ -54,28 +56,32 @@ def test_append_run_info(standard, extra1, extra2):
54
56
assert len (standard .metadata ["run_info" ]) == 3
55
57
56
58
57
- def test_save (standard , extra1 , extra2 , tmp_path ):
59
+ def test_save (standard , tmp_path ):
58
60
assert isinstance (standard .metadata ["run_info" ], dict )
59
- file_path = tmp_path / "new_standard.json"
60
-
61
- # make sure saving doesn't change the contents
62
- new_standard = Standards (file_path , auto_load = False )
61
+ new_file_path = tmp_path / "new_standard_1.json"
62
+ new_standard = Standards (new_file_path , auto_load = False )
63
63
new_standard .data = standard .data
64
64
new_standard .metadata = standard .metadata
65
- new_standard .save ()
66
- assert pathlib .Path .exists (file_path )
67
-
68
- newer_standard = Standards (file_path )
69
- assert newer_standard .data == standard .data
70
- assert newer_standard .metadata == standard .metadata
71
-
72
- newer_standard .append_run_info (extra1 )
73
- newer_standard .append_run_info (extra2 )
74
- newer_standard .save ()
75
- newer_standard .reload ()
76
-
77
- assert isinstance (newer_standard .metadata ["run_info" ], list )
78
- assert len (newer_standard .metadata ["run_info" ]) == 3
79
- assert newer_standard .metadata ["run_info" ][0 ] == standard .metadata ["run_info" ]
80
- assert newer_standard .metadata ["run_info" ][1 ] == extra1
81
- assert newer_standard .metadata ["run_info" ][2 ] == extra2
65
+ new_standard .save ("pytest" )
66
+ assert pathlib .Path .exists (new_file_path )
67
+ new_standard .reload ()
68
+ assert new_standard .metadata ["NOTICE" ] == "This file is auto-generated by pytest; avoid editing it manually."
69
+
70
+
71
+ def test_save_notice (standard , extra1 , extra2 , tmp_path ):
72
+ new_standard = copy .deepcopy (standard )
73
+ new_standard .path = tmp_path / "new_standard_2.json"
74
+ assert new_standard .data == standard .data
75
+ assert new_standard .metadata == standard .metadata
76
+
77
+ new_standard .append_run_info (extra1 )
78
+ new_standard .append_run_info (extra2 )
79
+ new_standard .save ("pytest again" )
80
+ new_standard .reload ()
81
+
82
+ assert isinstance (new_standard .metadata ["run_info" ], list )
83
+ assert new_standard .metadata ["NOTICE" ] == "This file is auto-generated by pytest again; avoid editing it manually."
84
+ assert len (new_standard .metadata ["run_info" ]) == 3
85
+ assert new_standard .metadata ["run_info" ][0 ] == standard .metadata ["run_info" ]
86
+ assert new_standard .metadata ["run_info" ][1 ] == extra1
87
+ assert new_standard .metadata ["run_info" ][2 ] == extra2
0 commit comments