1+ from os .path import normpath
12from typing import TYPE_CHECKING
23
34from cycode .cli .files_collector .path_documents import (
1011 from pyfakefs .fake_filesystem import FakeFilesystem
1112
1213
13- def test_walk_to_top () -> None :
14- path = '/a/b/c/d/e/f/g'
15- result = list (_walk_to_top (path ))
16- assert result == ['/a/b/c/d/e/f/g' , '/a/b/c/d/e/f' , '/a/b/c/d/e' , '/a/b/c/d' , '/a/b/c' , '/a/b' , '/a' , '/' ]
14+ # we are using normpath() in every test to provide multi-platform support
1715
18- path = '/a/b/c'
19- result = list (_walk_to_top (path ))
20- assert result == ['/a/b/c' , '/a/b' , '/a' , '/' ]
2116
22- path = '/a'
17+ def test_walk_to_top () -> None :
18+ path = normpath ('/a/b/c/d/e/f/g' )
19+ result = list (_walk_to_top (path ))
20+ assert result == [
21+ normpath ('/a/b/c/d/e/f/g' ),
22+ normpath ('/a/b/c/d/e/f' ),
23+ normpath ('/a/b/c/d/e' ),
24+ normpath ('/a/b/c/d' ),
25+ normpath ('/a/b/c' ),
26+ normpath ('/a/b' ),
27+ normpath ('/a' ),
28+ normpath ('/' ),
29+ ]
30+
31+ path = normpath ('/a' )
2332 result = list (_walk_to_top (path ))
24- assert result == ['/a' , '/' ]
33+ assert result == [normpath ( '/a' ), normpath ( '/' ) ]
2534
26- path = '/'
35+ path = normpath ( '/' )
2736 result = list (_walk_to_top (path ))
28- assert result == ['/' ]
37+ assert result == [normpath ( '/' ) ]
2938
30- path = 'a'
39+ path = normpath ( 'a' )
3140 result = list (_walk_to_top (path ))
32- assert result == ['a' ]
41+ assert result == [normpath ( 'a' ) ]
3342
3443
3544def _create_mocked_file_structure (fs : 'FakeFilesystem' ) -> None :
@@ -45,33 +54,33 @@ def test_collect_top_level_ignore_files(fs: 'FakeFilesystem') -> None:
4554 _create_mocked_file_structure (fs )
4655
4756 # Test with path inside the project
48- path = '/home/user/project/subdir'
57+ path = normpath ( '/home/user/project/subdir' )
4958 ignore_files = _collect_top_level_ignore_files (path )
5059
5160 assert len (ignore_files ) == 3
52- assert '/home/user/project/subdir/.gitignore' in ignore_files
53- assert '/home/user/project/.gitignore' in ignore_files
54- assert '/home/user/project/.cycodeignore' in ignore_files
61+ assert normpath ( '/home/user/project/subdir/.gitignore' ) in ignore_files
62+ assert normpath ( '/home/user/project/.gitignore' ) in ignore_files
63+ assert normpath ( '/home/user/project/.cycodeignore' ) in ignore_files
5564
5665 # Test with a path that does not have any ignore files
5766 fs .remove ('/home/user/project/.gitignore' )
58- path = '/home/user'
67+ path = normpath ( '/home/user' )
5968 ignore_files = _collect_top_level_ignore_files (path )
6069
6170 assert len (ignore_files ) == 0
6271
6372 # Test with path at the top level with no ignore files
64- path = '/home/user/.git'
73+ path = normpath ( '/home/user/.git' )
6574 ignore_files = _collect_top_level_ignore_files (path )
6675
6776 assert len (ignore_files ) == 0
6877
6978 # Test with path at the top level with a .gitignore
70- path = '/home/user/project'
79+ path = normpath ( '/home/user/project' )
7180 ignore_files = _collect_top_level_ignore_files (path )
7281
7382 assert len (ignore_files ) == 1
74- assert '/home/user/project/.cycodeignore' in ignore_files
83+ assert normpath ( '/home/user/project/.cycodeignore' ) in ignore_files
7584
7685
7786def test_get_global_ignore_patterns (fs : 'FakeFilesystem' ) -> None :
0 commit comments