diff --git a/tests/test_examples.py b/tests/test_examples.py index b9084574..a08e239e 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -25,7 +25,7 @@ from zipline.testing import test_resource_path from zipline.testing.fixtures import WithTmpDir, ZiplineTestCase from zipline.testing.predicates import assert_equal from zipline.utils.cache import dataframe_cache -from zipline.utils.paths import ensure_file +from zipline.utils.paths import update_modified_time # Otherwise the next line sometimes complains about being run too late. @@ -57,7 +57,11 @@ class ExamplesTests(WithTmpDir, ZiplineTestCase): market_data = ('SPY_benchmark.csv', 'treasury_curves.csv') for data in market_data: - ensure_file(cls.tmpdir.getpath('example_data/root/data/' + data)) + update_modified_time( + cls.tmpdir.getpath( + 'example_data/root/data/' + data + ) + ) @parameterized.expand(sorted(examples.EXAMPLE_MODULES)) def test_example(self, example_name): diff --git a/zipline/utils/paths.py b/zipline/utils/paths.py index 160de901..79e0e28a 100644 --- a/zipline/utils/paths.py +++ b/zipline/utils/paths.py @@ -48,7 +48,7 @@ def ensure_directory_containing(path): def ensure_file(path): """ Ensure that a file exists. This will create any parent directories needed - and create an empty file if it does not exists. + and create an empty file if it does not exist. Parameters ---------- @@ -59,6 +59,22 @@ def ensure_file(path): open(path, 'a+').close() # touch the file +def update_modified_time(path, times=None): + """ + Updates the modified time of an existing file. This will create any + parent directories needed and create an empty file if it does not exist. + + Parameters + ---------- + path : str + The file path to update. + times : tuple + A tuple of size two; access time and modified time + """ + ensure_directory_containing(path) + os.utime(path, times) + + def last_modified_time(path): """ Get the last modified time of path as a Timestamp.