diff --git a/tests/shared.py b/tests/shared.py index 3491f16..21f0825 100644 --- a/tests/shared.py +++ b/tests/shared.py @@ -20,6 +20,13 @@ import peru.main test_resources = Path(__file__).parent.resolve() / 'resources' +# Colons are a reserved character on Windows, so tests that cover filenames +# with colons need to do something else. +COLON = ':' +if os.name == 'nt': + COLON = 'COLON_' + + def make_synchronous(f): '''This lets you turn coroutines into regular functions and call them from synchronous code, so for example test methods can be coroutines. It does diff --git a/tests/test_cache.py b/tests/test_cache.py index df12287..ff10812 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -3,7 +3,8 @@ import os import time import peru.cache -from shared import assert_contents, create_dir, make_synchronous, PeruTest +from shared import assert_contents, create_dir, make_synchronous, PeruTest, \ + COLON class CacheTest(PeruTest): @@ -77,19 +78,19 @@ class CacheTest(PeruTest): # with a leading ./ all_content = {'foo': '', 'bar': '', - ':baz/bing': ''} + COLON + 'baz/bing': ''} test_dir = create_dir(all_content) tree = yield from self.cache.import_tree( - test_dir, picks=['foo', ':baz']) + test_dir, picks=['foo', COLON + 'baz']) expected_content = {'foo': '', - ':baz/bing': ''} + COLON + 'baz/bing': ''} out_dir = create_dir() yield from self.cache.export_tree(tree, out_dir) assert_contents(out_dir, expected_content) # Repeat the same test with an exclude, again with a colon. tree = yield from self.cache.import_tree( - test_dir, excludes=['foo', ':baz']) + test_dir, excludes=['foo', COLON + 'baz']) expected_content = {'bar': ''} out_dir = create_dir() yield from self.cache.export_tree(tree, out_dir) @@ -207,17 +208,17 @@ class CacheTest(PeruTest): # Include a leading colon, to check that we escape pathspecs correctly # with a leading ./ all_content = {'a': 'foo', - ':b/c': 'bar'} + COLON + 'b/c': 'bar'} test_dir = create_dir(all_content) tree = yield from self.cache.import_tree(test_dir) a_content = yield from self.cache.read_file(tree, 'a') - bc_content = yield from self.cache.read_file(tree, ':b/c') + bc_content = yield from self.cache.read_file(tree, COLON + 'b/c') self.assertEqual(b'foo', a_content) self.assertEqual(b'bar', bc_content) with self.assertRaises(FileNotFoundError): yield from self.cache.read_file(tree, 'nonexistent') with self.assertRaises(IsADirectoryError): - yield from self.cache.read_file(tree, ':b') + yield from self.cache.read_file(tree, COLON + 'b') # A helper method for several tests below below. @asyncio.coroutine diff --git a/tests/test_rule.py b/tests/test_rule.py index aee0a4e..bceec0b 100644 --- a/tests/test_rule.py +++ b/tests/test_rule.py @@ -4,6 +4,7 @@ from peru import cache from peru import rule import shared +from shared import COLON class RuleTest(shared.PeruTest): @@ -13,7 +14,7 @@ class RuleTest(shared.PeruTest): self.cache_dir = shared.create_dir() self.cache = yield from cache.Cache(self.cache_dir) # Include a leading colon to test that we prepend ./ to pathspecs. - self.content = {'a': 'foo', 'b/c': 'bar', ':d': 'baz'} + self.content = {'a': 'foo', 'b/c': 'bar', COLON + 'd': 'baz'} self.content_dir = shared.create_dir(self.content) self.content_tree = yield from self.cache.import_tree(self.content_dir) self.entries = yield from self.cache.ls_tree( @@ -32,7 +33,7 @@ class RuleTest(shared.PeruTest): 'b/c': 'foo', 'x': 'foo', 'y/c': 'bar', - ':d': 'baz', + COLON + 'd': 'baz', }) @shared.make_synchronous @@ -45,7 +46,7 @@ class RuleTest(shared.PeruTest): yield from shared.assert_tree_contents(self.cache, tree, { 'a/c': 'bar', 'b/a': 'foo', - ':d': 'baz', + COLON + 'd': 'baz', }) @shared.make_synchronous @@ -53,22 +54,22 @@ class RuleTest(shared.PeruTest): drop_dir = yield from rule.drop_files( self.cache, self.content_tree, ['b']) yield from shared.assert_tree_contents( - self.cache, drop_dir, {'a': 'foo', ':d': 'baz'}) + self.cache, drop_dir, {'a': 'foo', COLON + 'd': 'baz'}) drop_file = yield from rule.drop_files( self.cache, self.content_tree, ['a']) yield from shared.assert_tree_contents( - self.cache, drop_file, {'b/c': 'bar', ':d': 'baz'}) + self.cache, drop_file, {'b/c': 'bar', COLON + 'd': 'baz'}) drop_colon = yield from rule.drop_files( - self.cache, self.content_tree, [':d']) + self.cache, self.content_tree, [COLON + 'd']) yield from shared.assert_tree_contents( self.cache, drop_colon, {'a': 'foo', 'b/c': 'bar'}) globs = yield from rule.drop_files( self.cache, self.content_tree, ['**/c', '**/a']) yield from shared.assert_tree_contents( - self.cache, globs, {':d': 'baz'}) + self.cache, globs, {COLON + 'd': 'baz'}) @shared.make_synchronous def test_pick(self): @@ -83,9 +84,9 @@ class RuleTest(shared.PeruTest): self.cache, pick_file, {'a': 'foo'}) pick_colon = yield from rule.pick_files( - self.cache, self.content_tree, [':d']) + self.cache, self.content_tree, [COLON + 'd']) yield from shared.assert_tree_contents( - self.cache, pick_colon, {':d': 'baz'}) + self.cache, pick_colon, {COLON + 'd': 'baz'}) globs = yield from rule.pick_files( self.cache, self.content_tree, ['**/c', '**/a'])