Skip to content

Commit

Permalink
TST: Updated modified time of market data in test_examples
Browse files Browse the repository at this point in the history
  • Loading branch information
buinvest authored and freddiev4 committed Jun 7, 2017
1 parent 1e28743 commit 5160b11
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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.
Expand Down Expand Up @@ -57,7 +57,11 @@ def init_class_fixtures(cls):

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):
Expand Down
18 changes: 17 additions & 1 deletion zipline/utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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.
Expand Down

0 comments on commit 5160b11

Please sign in to comment.