Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows support #25

Draft
wants to merge 5 commits into
base: python3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci-python3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
os: [ ubuntu-20.04, ubuntu-18.04 ]
os: [ ubuntu-20.04, ubuntu-18.04, macos-10.15 ]
python-version: [ '3.5', '3.6', '3.7', '3.8', '3.9' ]

# Steps represent a sequence of tasks that will be executed as part of the job
Expand All @@ -32,9 +32,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install test dependencies
- name: Install Linux test dependencies
if: runner.os == 'Linux'
run: |
sudo apt install coreutils cksfv

- name: Install Python test dependencies
run: |
pip install pyroma
pip install check-manifest
pip install twine
Expand Down
12 changes: 6 additions & 6 deletions lib/cfv/osutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ def path_split(filename):
def strippath(filename, num='a', _splitdrivere=re.compile(r'[a-z]:[/\\]', re.I)):
"""Strip off path components from the left side of the filename.

>>> strippath(os.path.join('c:','foo','bar','baz'))
>>> strippath(os.path.join('c:' + os.sep,'foo','bar','baz'))
'baz'
>>> path_split(strippath(os.path.join('c:','foo','bar','baz'), 'n'))
>>> path_split(strippath(os.path.join('c:' + os.sep,'foo','bar','baz'), 'n'))
['c:', 'foo', 'bar', 'baz']
>>> path_split(strippath(os.path.join('c:','foo','bar','baz'), 0))
>>> path_split(strippath(os.path.join('c:' + os.sep,'foo','bar','baz'), 0))
['foo', 'bar', 'baz']
>>> path_split(strippath(os.path.join(os.sep,'foo','bar','baz'), 0))
['foo', 'bar', 'baz']
>>> path_split(strippath(os.path.join('c:','foo','bar','baz'), 1))
>>> path_split(strippath(os.path.join('c:' + os.sep,'foo','bar','baz'), 1))
['bar', 'baz']
>>> strippath(os.path.join('c:','foo','bar','baz'), 2)
>>> strippath(os.path.join('c:' + os.sep,'foo','bar','baz'), 2)
'baz'
>>> strippath(os.path.join('c:','foo','bar','baz'), 3)
>>> strippath(os.path.join('c:' + os.sep,'foo','bar','baz'), 3)
'baz'
"""
if num == 'a': # split all the path off
Expand Down
2 changes: 2 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,7 @@ def copytree(src, dst, ignore=None):

# copy the testdata into a temp dir in order to avoid .svn dirs breaking some tests
tmpdatapath = tempfile.mkdtemp()
orig_path = os.getcwd()
try:
copytree(cfvtest.datapath, tmpdatapath, ignore=['.svn'])
os.chdir(tmpdatapath) # do this after the setcfv, since the user may have specified a relative path
Expand All @@ -1889,4 +1890,5 @@ def copytree(src, dst, ignore=None):
failed += all_tests()
sys.exit(failed)
finally:
os.chdir(orig_path)
shutil.rmtree(tmpdatapath)
44 changes: 30 additions & 14 deletions test/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def mkfile(self, name, contents):
f.write(contents)
return name

def readfile(self, name):
with open(name, 'rt') as f:
return f.read()


class AbsPathKeyTest(AbsTestCase):
def test_get_path_key(self):
Expand Down Expand Up @@ -132,31 +136,43 @@ def test_rename(self):
class RelPathKeyTest(RelTestCase):
def test_nocase_findfile(self):
cache = FileInfoCache()
a1 = self.mkfile('aAaA/AaA1', '1')
self.mkfile('aAaA/Aaa2', '2')
self.mkfile('aAaA/AAa2', '3')
a1 = self.mkfile(os.path.join('aAaA', 'AaA1'), '1')
self.mkfile(os.path.join('aAaA', 'Aaa2'), '2')
self.mkfile(os.path.join('aAaA', 'AAa2'), '3')

a2_content = self.readfile(os.path.join('aAaA', 'Aaa2'))
self.assertIn(a2_content, ('2', '3'))
fs_case_sensitive = a2_content == '2'
if not fs_case_sensitive:
print('Skipping some tests due to case-insensitive filesystem')

self.assertEquals(a1, cache.nocase_findfile(self.mkpath('aaAA/aaa1')))
self.assertEquals(a1, cache.nocase_findfile(self.mkpath(os.path.join('aaAA', 'aaa1'))))
with self.assertRaises(IOError) as cm:
cache.nocase_findfile(self.mkpath('aaAb/aaa1'))
cache.nocase_findfile(self.mkpath(os.path.join('aaAb', 'aaa1')))
self.assertEquals(errno.ENOENT, cm.exception.errno)

with self.assertRaises(IOError) as cm:
cache.nocase_findfile(self.mkpath('aaAA/aab1'))
cache.nocase_findfile(self.mkpath(os.path.join('aaAA', 'aab1')))
self.assertEquals(errno.ENOENT, cm.exception.errno)

with self.assertRaises(IOError) as cm:
cache.nocase_findfile(self.mkpath('aaAA/aaa2'))
self.assertEquals(errno.EEXIST, cm.exception.errno)
if fs_case_sensitive:
with self.assertRaises(IOError) as cm:
cache.nocase_findfile(self.mkpath(os.path.join('aaAA', 'aaa2')))
self.assertEquals(errno.EEXIST, cm.exception.errno)

def test_nocase_findfile_parent(self):
cache = FileInfoCache()
self.mkfile('aaaA/aaA1', '1')
self.mkfile('aAaA/aaa2', '2')
self.mkfile(os.path.join('aaaA', 'aaA1'), '1')
fs_case_sensitive = not os.path.exists('aAaA')
self.mkfile(os.path.join('aAaA', 'aaa2'), '2')

if not fs_case_sensitive:
print('Skipping some tests due to case-insensitive filesystem')

# right now we don't handle this case, though it would be possible
# to generate all possible matches and see if the number is exactly
# one.
with self.assertRaises(IOError) as cm:
cache.nocase_findfile(self.mkpath('aaAA/aaa2'))
self.assertEquals(errno.EEXIST, cm.exception.errno)
if fs_case_sensitive:
with self.assertRaises(IOError) as cm:
cache.nocase_findfile(self.mkpath(os.path.join('aaAA', 'aaa2')))
self.assertEquals(errno.EEXIST, cm.exception.errno)