示例#1
0
    def test_exists_path(self):
        folder_path = os.path.abspath(os.path.dirname(__file__))

        self.assertFalse(path.exists(folder_path))
        self.assertFalse(path.exists(path.join(folder_path, __file__), True))
        self.assertFalse(path.exists('/unexistent/folder', True))
        self.assertFalse(path.exists('/unexistent/folder', True))

        self.assertTrue(path.exists(folder_path, True))
        self.assertTrue(path.exists(path.join(folder_path, __file__)))
示例#2
0
 def test_join(self):
     tests = [
         {
             'paths': [],
             'expected': ''
         },
         {
             'paths': [''],
             'expected': ''
         },
         {
             'paths': ['', ''],
             'expected': ''
         },
         {
             'paths': ['a', ''],
             'expected': os.path.join('a', '')
         },
         {
             'paths': ['', 'a'],
             'expected': 'a'
         },
         {
             'paths': ['a', 'b'],
             'expected': os.path.join('a', 'b')
         },
     ]
     for test in tests:
         self.assertEqual(test['expected'], path.join(*test['paths']))
示例#3
0
def get_output(f):
    return path.join(os.path.abspath(os.path.dirname(__file__)), 'outputs', f)
示例#4
0
    def test_list_files(self):
        self.assertEqual(len(path.list_files(path.join('unexistent', 'path'))),
                         0)
        self.assertListEqual(path.list_files(path.join('unexistent', 'path')),
                             [])

        folder_path = os.path.abspath(os.path.dirname(__file__))
        base_path = path.join(folder_path, 'foo')
        self.create_folder(path.join(folder_path, 'foo', 'bar'))
        paths = [
            ['foo.txt'],
            ['bar.rb'],
            ['bar', 'foo.txt'],
            ['bar', 'foo.py'],
            ['bar', 'main.go'],
            ['bar', 'other.go'],
        ]

        for p in paths:
            with open(path.join(base_path, *p), 'a') as f:
                f.close()

        files = path.list_files(base_path)
        self.assertEqual(6, len(files))
        expected = [
            path.join(folder_path, 'foo', 'bar.rb'),
            path.join(folder_path, 'foo', 'foo.txt'),
            path.join(folder_path, 'foo', 'bar', 'other.go'),
            path.join(folder_path, 'foo', 'bar', 'foo.txt'),
            path.join(folder_path, 'foo', 'bar', 'foo.py'),
            path.join(folder_path, 'foo', 'bar', 'main.go'),
        ]
        self.assertListEqual(sorted(expected), sorted(files))
        self.delete_folder(base_path)