Tests that writing a CSV of a ``Statistics`` object and then reading that CSV again returns the same object.
(ok_small, tmp_path)
| 5 | |
| 6 | |
| 7 | def test_csv_serialises_correctly(ok_small, tmp_path): |
| 8 | """ |
| 9 | Tests that writing a CSV of a ``Statistics`` object and then reading that |
| 10 | CSV again returns the same object. |
| 11 | """ |
| 12 | sol = Solution(ok_small, [[1, 2], [3, 4]]) |
| 13 | cost_eval = CostEvaluator([20], 6, 6) |
| 14 | |
| 15 | collected_stats = Statistics() |
| 16 | for idx in range(10): # populate the statistics object |
| 17 | collected_stats.collect(sol, sol, sol, cost_eval) |
| 18 | |
| 19 | csv_path = tmp_path / "test.csv" |
| 20 | assert_(not csv_path.exists()) |
| 21 | |
| 22 | # Write the collected statistics to the CSV file location, and check that |
| 23 | # the file now does exist. |
| 24 | collected_stats.to_csv(csv_path) |
| 25 | assert_(csv_path.exists()) |
| 26 | |
| 27 | # Now read them back in, and check that the newly read object is the same |
| 28 | # as the previously written object. |
| 29 | read_stats = Statistics.from_csv(csv_path) |
| 30 | assert_equal(collected_stats, read_stats) |
| 31 | |
| 32 | |
| 33 | @pytest.mark.parametrize("num_iterations", [0, 5]) |
nothing calls this directly
no test coverage detected