MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_csv_serialises_correctly

Function test_csv_serialises_correctly

tests/test_Statistics.py:7–30  ·  view source on GitHub ↗

Tests that writing a CSV of a ``Statistics`` object and then reading that CSV again returns the same object.

(ok_small, tmp_path)

Source from the content-addressed store, hash-verified

5
6
7def 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])

Callers

nothing calls this directly

Calls 6

collectMethod · 0.95
to_csvMethod · 0.95
SolutionClass · 0.90
CostEvaluatorClass · 0.90
StatisticsClass · 0.90
from_csvMethod · 0.80

Tested by

no test coverage detected