Ejemplo n.º 1
0
 def test_exclude(self):
     dir_path = os.path.dirname(os.path.realpath(__file__))
     total_count = 0
     exclude_count = 0
     for path in ops.find(dir_path):
         total_count += 1
     for path in ops.find(dir_path).exclude(name='test_find.py'):
         exclude_count += 1
     self.assertEqual(exclude_count + 1, total_count)
Ejemplo n.º 2
0
 def test_add_rule_time(self):
     find = ops.find('.')
     find._add_rule({'atime__year': 2010})
     find._add_rule({'ctime__month': 5})
     find._add_rule({'mtime__day': 1})
     self.assertEqual(len(find.rules), 3)
     self.assertTrue(isinstance(find.rules[0], ops._FindTimeRule))
     self.assertTrue(isinstance(find.rules[1], ops._FindTimeRule))
     self.assertTrue(isinstance(find.rules[2], ops._FindTimeRule))
Ejemplo n.º 3
0
    def test_top_down(self):
        self.setup_directory()

        list1 = list(ops.find(self.workspace.path))
        list2 = list(ops.find(self.workspace.path, top_down=True))
        list3 = list(ops.find(self.workspace.path, no_peek=True, top_down=True))

        self.assertEqual(len(list1), 22)
        self.assertEqual(len(list2), len(list1))
        self.assertEqual(len(list3), len(list2))

        self.assertNotEqual(list2[0], list1[0])
        self.assertNotEqual(list2[-1], list1[-1])

        for i, v in enumerate(list2):
            self.assertEqual(list3[i], v)

        list1.sort()
        list2.sort()
        for i, v in enumerate(list1):
            self.assertEqual(list2[i], v)
Ejemplo n.º 4
0
 def test_filter(self):
     dir_path = os.path.dirname(os.path.realpath(__file__))
     count = 0
     for path in ops.find(dir_path).filter(name='test_find.py'):
         count += 1
     self.assertEqual(count, 1)
Ejemplo n.º 5
0
 def test_add_rule_file(self):
     find = ops.find('.')
     find._add_rule({'file': True})
     self.assertEqual(len(find.rules), 1)
     self.assertTrue(isinstance(find.rules[0], ops._FindFileRule))
Ejemplo n.º 6
0
 def test_add_rule_directory(self):
     find = ops.find('.')
     find._add_rule({'directory': True})
     self.assertEqual(len(find.rules), 1)
     self.assertTrue(isinstance(find.rules[0], ops._FindDirectoryRule))
Ejemplo n.º 7
0
 def test_add_rule_name(self):
     find = ops.find('.')
     find._add_rule({'name': '*.pyc'})
     self.assertEqual(len(find.rules), 1)
     self.assertTrue(isinstance(find.rules[0], ops._FindNameRule))