def test_time_selection(self): check = tools.check_timestamp_unchanged('check_atime', 'atime') assert 'st_atime' == check._timeattr check = tools.check_timestamp_unchanged('check_ctime', 'ctime') assert 'st_ctime' == check._timeattr check = tools.check_timestamp_unchanged('check_mtime', 'mtime') assert 'st_mtime' == check._timeattr pytest.raises( ValueError, tools.check_timestamp_unchanged, 'check_invalid_time', 'foo')
def task_on_foo_changed(): # will execute if foo or its metadata is modified return { 'actions': ['echo foo modified'], 'task_dep': ['create_foo'], 'uptodate': [check_timestamp_unchanged('foo', 'ctime')], }
def run_tests(backend, pytest_args, cwd): result = '{}/results/{}.txt'.format(root, backend) pytest = ('py.test --neurons nengo.Direct,nengo.LIF --slow --plots ' '--analytics -- {} > {}'.format(pytest_args, result)) action = CmdAction(pytest, cwd=cwd) return {'name': backend, 'actions': ['rm -f {}'.format(result), action], 'targets': [result], 'uptodate': [check_timestamp_unchanged(cwd)]}
def test_op_bad_custom(self, monkeypatch, checked_file): # handling misbehaving custom operators def bad_op(prev_time, current_time): raise Exception('oops') check = tools.check_timestamp_unchanged(checked_file, cmp_op=bad_op) t = task.Task("TaskX", None, uptodate=[check]) # fake values saved from previous run task_values = {check._key: 1} # needs any value different from None pytest.raises(Exception, check, t, task_values)
def test_op_ge(self, monkeypatch, checked_file): check = tools.check_timestamp_unchanged(checked_file,cmp_op=operator.ge) t = task.Task("TaskX", None, uptodate=[check]) # no stored value/first run assert False == check(t, t.values) # value just stored is equal to itself t.save_extra_values() assert True == check(t, t.values) # stored timestamp less than current, up to date future_time = list(six.itervalues(t.values))[0] + 100 monkeypatch.setattr(check, '_get_time', lambda: future_time) assert False == check(t, t.values)
def task_docs(): """ Build documentation using sphinx. """ def cmd_build(): """ Build docs """ # change to ``docs/`` sh.cd('docs') # run ``make html`` output = sh.make('html') sh.cd('..') return { 'actions': [(cmd_build, )], 'file_dep': ["docs/index.rst"], 'targets': ["docs/_build"], 'uptodate': [check_timestamp_unchanged('docs')] }
def test_multiple_checks(self): # handling multiple checks on one file (should save values in such way # they don't override each other) check_a = tools.check_timestamp_unchanged('check_multi', 'atime') check_m = tools.check_timestamp_unchanged('check_multi', 'mtime') assert check_a._key != check_m._key
def test_file_missing(self): check = tools.check_timestamp_unchanged('no_such_file') t = task.Task("TaskX", None, uptodate=[check]) # fake values saved from previous run task_values = {check._key: 1} # needs any value different from None pytest.raises(OSError, check, t, task_values)
def test_multiple_checks(self): # handling multiple checks on one file (should save values in such way # they don't override each other) check_a = tools.check_timestamp_unchanged('check_multi', 'atime') check_m = tools.check_timestamp_unchanged('check_multi', 'mtime') assert check_a._key != check_m._key
def test_file_missing(self): check = tools.check_timestamp_unchanged('no_such_file') t = task.Task("TaskX", None, uptodate=[check]) # fake values saved from previous run task_values = {check._key: 1} # needs any value different from None pytest.raises(OSError, check, t, task_values)