Beispiel #1
0
 def test_include_files_and_reread(self):
     x = sd.fakedir_fromstring(example)
     y = x.seedir(printout=False, include_files=['app.py', 'view.py'],
                  regex=False)
     z = sd.fakedir_fromstring(y)
     self.assertEqual(set(z.get_child_names()),
                      set(['app.py', 'view.py', 'test', ]))
Beispiel #2
0
 def test_mask_fakedir_fromstring(self):
     x = sd.fakedir_fromstring(example)
     s = x.seedir(printout=False,
                  mask=lambda x: not x.name[0] == '_',
                  style='spaces',
                  indent=4)
     self.assertEqual(no_init, s)
Beispiel #3
0
 def test_many_randomdirs(self):
     seeds = range(1000)
     for i in seeds:
         r = sd.randomdir(seed=i)
         s = r.seedir(printout=False)
         f = sd.fakedir_fromstring(s)
         self.assertEqual(s, f.seedir(printout=False))
Beispiel #4
0
 def test_limit0_beyond_content(self):
     ans = limit0_beyond_content
     f = sd.fakedir_fromstring(large_example)
     s1 = f.seedir(printout=False, itemlimit=0, beyond='content')
     s2 = f.seedir(printout=False, depthlimit=0, beyond='content')
     self.assertEqual(ans, s1)
     self.assertEqual(ans, s2)
Beispiel #5
0
 def test_limit0_nobeyond(self):
     ans = limit0_nobeyond
     f = sd.fakedir_fromstring(large_example)
     s1 = f.seedir(printout=False, itemlimit=0)
     s2 = f.seedir(printout=False, depthlimit=0)
     self.assertEqual(ans, s1)
     self.assertEqual(ans, s2)
Beispiel #6
0
 def test_walk_apply(self):
     def add_0(f):
         f.name += ' 0'
     x = sd.fakedir_fromstring(example)
     x.walk_apply(add_0)
     for f in x.get_child_names():
         self.assertEqual(f[-1], '0')
Beispiel #7
0
 def test_complex_sort(self):
     ans = complex_sort
     params = dict(sort=True, sort_reverse=True,
                   sort_key = lambda x: len(x), first='files')
     f = sd.fakedir_fromstring(large_example)
     s = f.seedir(printout=False,**params)
     self.assertEqual(ans, s)
Beispiel #8
0
 def test_depth_setting(self):
     x = sd.fakedir_fromstring(example)
     x['test'].create_folder('A')
     x['test/A'].create_folder('B')
     x['test/A/B'].create_file('boris.txt')
     self.assertEqual(x['test/A/B/boris.txt'].depth, 4)
     x['test/A/B/boris.txt'].parent = x
     self.assertEqual(x['boris.txt'].depth, 1)
Beispiel #9
0
 def test_depthlimit1_beyond_content_exclude(self):
     ans = depthlimit1_beyond_content_exclude
     f = sd.fakedir_fromstring(large_example)
     s = f.seedir(printout=False,
                  depthlimit=1,
                  beyond='content',
                  exclude_files='.*\.txt',
                  regex=True)
     self.assertEqual(ans, s)
Beispiel #10
0
 def test_complex_inclusion(self):
     ans = complex_inclusion
     params = dict(include_folders=['sandal', 'scrooge', 'pedantic'],
                   exclude_folders='sandal',
                   exclude_files='^Vogel',
                   include_files='^.[oi]',
                   regex=True)
     f = sd.fakedir_fromstring(large_example)
     s = f.seedir(printout=False,**params)
     self.assertEqual(ans, s)
Beispiel #11
0
    def test_copy_unlinked(self):
        def pallindrome(f):
            f.name = f.name + f.name[::-1]
        x = sd.fakedir_fromstring(large_example)

        before = x.seedir(printout=False)

        y = x.copy()
        y.walk_apply(pallindrome)

        after = x.seedir(printout=False)
        self.assertEqual(before, after)
Beispiel #12
0
 def test_depthlimit1(self):
     ans = depthlimit1
     f = sd.fakedir_fromstring(large_example)
     s = f.seedir(printout=False, depthlimit=1)
     self.assertEqual(ans, s)
Beispiel #13
0
 def test_exclude_files_and_reread(self):
     x = sd.fakedir_fromstring(example)
     y = x.seedir(printout=False, exclude_files='.*\..*', regex=True)
     z = sd.fakedir_fromstring(y)
     self.assertEqual(set(z.get_child_names()), set(['test']))
Beispiel #14
0
 def test_set_parent(self):
     x = sd.fakedir_fromstring(example)
     x['test/test_app.py'].parent = x
     self.assertTrue('test_app.py' in x.get_child_names())
Beispiel #15
0
 def test_sort_fakedir(self):
     x = sd.fakedir_fromstring(example).listdir()
     sort = sort_fakedir(x, sort_reverse=True, sort_key=lambda x: x[1])
     sort = [f.name for f in sort]
     correct = ['app.py', 'view.py', 'test', '__init__.py']
     self.assertEqual(sort, correct)
Beispiel #16
0
 def test_count_fake_items(self):
     x = sd.fakedir_fromstring(example)
     self.assertEqual(count_fakedirs(x.listdir()), 1)
     self.assertEqual(count_fakefiles(x.listdir()), 3)
Beispiel #17
0
 def test_parse_comments(self):
     x = sd.fakedir_fromstring(example)
     y = sd.fakedir_fromstring(example_with_comments)
     z = sd.fakedir_fromstring(example_with_comments, parse_comments=False)
     self.assertEqual(x.get_child_names(), y.get_child_names())
     self.assertNotEqual(x.get_child_names(), z.get_child_names())
Beispiel #18
0
 def test_read_string(self):
     x = sd.fakedir_fromstring(example)
     self.assertTrue(isinstance(x, sd.FakeDir))
Beispiel #19
0
 def test_depthlimit1_beyond_content(self):
     ans = depthlimit1_beyond_content
     f = sd.fakedir_fromstring(large_example)
     s = f.seedir(printout=False, depthlimit=1, beyond='content')
     self.assertEqual(ans, s)