示例#1
0
 def test_ne(self):
     for op in ['ne', '!=', '<>']:
         f1 = FileRule('name', op, os.path.basename(self.file_path),
                       'exclude')
         f2 = FileRule('name', op, "...", 'exclude')
         self.assertEqual(f2.test(self.file_entry), "exclude")
         self.assertEqual(f1.test(self.file_entry), None)
示例#2
0
 def test_regexp(self):
     self.file_entry.pathname = "test_file.txt"
     f = FileRule("name", "regexp", "test.*", "include")
     self.assertEqual(f.test(self.file_entry), "include")
     f = FileRule("name", "regexp", "test*", "include")
     self.assertEqual(f.test(self.file_entry), None)
     self.assertRaises(InvalidRegularExpression, self.regexp_invalid)
示例#3
0
 def test_regexp(self):
     self.file_entry.pathname = "test_file.txt"
     f = FileRule('name', 'regexp', "test.*", 'include')
     self.assertEqual(f.test(self.file_entry), 'include')
     f = FileRule('name', 'regexp', "test*", 'include')
     self.assertEqual(f.test(self.file_entry), None)
     self.assertRaises(InvalidRegularExpression, self.regexp_invalid)
示例#4
0
    def test_eq(self):

        for op in ["eq", "=", "=="]:
            f1 = FileRule("name", op, os.path.basename(self.file_path), "include")
            f2 = FileRule("name", op, "...", "include")
            self.assertEqual(f1.test(self.file_entry), "include")
            self.assertEqual(f2.test(self.file_entry), None)
示例#5
0
    def test_eq(self):

        for op in ['eq', '=', '==']:
            f1 = FileRule('name', op, os.path.basename(self.file_path),
                          'include')
            f2 = FileRule('name', op, "...", 'include')
            self.assertEqual(f1.test(self.file_entry), "include")
            self.assertEqual(f2.test(self.file_entry), None)
示例#6
0
 def test_gte(self):
     for op in ['gte', '>=']:
         f1 = FileRule('mtime', op,
                       format_datetime(time()-3600), 'exclude')
         f2 = FileRule('mtime', op,
                       format_datetime(time()+3600), 'exclude')
         self.assertEqual(f1.test(self.file_entry), 'exclude')
         self.assertEqual(f2.test(self.file_entry), None)
示例#7
0
 def test_lte(self):
     self.file_entry.ctime = int(self.file_entry.ctime)
     f1 = FileRule('ctime', 'lte', format_datetime(self.file_entry.ctime),
                   'include')
     f2 = FileRule('ctime', 'lte', format_datetime(time() - 3600),
                   'include')
     f3 = FileRule('ctime', 'eq', format_datetime(self.file_entry.ctime),
                   'include')
     self.assertEqual(f1.test(self.file_entry), 'include')
     self.assertEqual(f2.test(self.file_entry), None)
     self.assertEqual(f3.test(self.file_entry), 'include')
示例#8
0
    def test_match(self):
        f1 = FileRule("name", "match", "*", "include")
        f2 = FileRule("name", "match", "", "include")
        f3 = FileRule("name", "match", os.path.basename(self.file_entry.pathname), "include")
        self.assertEqual(f1.test(self.file_entry), "include")
        self.assertEqual(f2.test(self.file_entry), None)
        self.assertEqual(f3.test(self.file_entry), "include")

        file_entry = self.file_entry.clone()
        file_entry.pathname = "t.test"
        f = FileRule("name", "match", "*.test", "include")
        self.assertEqual(f.test(file_entry), "include")
        file_entry.pathname = "test"
        self.assertEqual(f.test(file_entry), None)
示例#9
0
 def test_regexp(self):
     self.file_entry.pathname = "test_file.txt"
     f = FileRule('name', 'regexp', "test.*", 'include')
     self.assertEqual(f.test(self.file_entry), 'include')
     f = FileRule('name', 'regexp', "test*", 'include')
     self.assertEqual(f.test(self.file_entry), None)
     self.assertRaises(InvalidRegularExpression, self.regexp_invalid)
示例#10
0
 def test_ne(self):
     for op in ['ne', '!=', '<>']:
         f1 = FileRule('name', op, os.path.basename(self.file_path),
                       'exclude')
         f2 = FileRule('name', op, "...", 'exclude')
         self.assertEqual(f2.test(self.file_entry), "exclude")
         self.assertEqual(f1.test(self.file_entry), None)
示例#11
0
    def test_eq(self):

        for op in ['eq', '=', '==']:
            f1 = FileRule('name', op, os.path.basename(self.file_path),
                          'include')
            f2 = FileRule('name', op, "...", 'include')
            self.assertEqual(f1.test(self.file_entry), "include")
            self.assertEqual(f2.test(self.file_entry), None)
示例#12
0
 def test_lte(self):
     self.file_entry.ctime = int(self.file_entry.ctime)
     f1 = FileRule("ctime", "lte", format_datetime(self.file_entry.ctime), "include")
     f2 = FileRule("ctime", "lte", format_datetime(time() - 3600), "include")
     f3 = FileRule("ctime", "eq", format_datetime(self.file_entry.ctime), "include")
     self.assertEqual(f1.test(self.file_entry), "include")
     self.assertEqual(f2.test(self.file_entry), None)
     self.assertEqual(f3.test(self.file_entry), "include")
示例#13
0
 def test_gte(self):
     for op in ['gte', '>=']:
         f1 = FileRule('mtime', op, format_datetime(time() - 3600),
                       'exclude')
         f2 = FileRule('mtime', op, format_datetime(time() + 3600),
                       'exclude')
         self.assertEqual(f1.test(self.file_entry), 'exclude')
         self.assertEqual(f2.test(self.file_entry), None)
示例#14
0
 def test_lte(self):
     self.file_entry.ctime = int(self.file_entry.ctime)
     f1 = FileRule('ctime', 'lte',
                   format_datetime(self.file_entry.ctime), 'include')
     f2 = FileRule('ctime', 'lte',
                   format_datetime(time()-3600), 'include')
     f3 = FileRule('ctime', 'eq',
                   format_datetime(self.file_entry.ctime), 'include')
     self.assertEqual(f1.test(self.file_entry), 'include')
     self.assertEqual(f2.test(self.file_entry), None)
     self.assertEqual(f3.test(self.file_entry), 'include')
示例#15
0
    def test_size(self):
        self.file_entry.size = 2
        for unit in ["k", "M", "G"]:

            f = FileRule("size", ">", "1" + unit, "include")
            self.assertEqual(f.test(self.file_entry), None)
            f = FileRule("size", "<", "1" + unit, "include")
            self.assertEqual(f.test(self.file_entry), "include")

            self.file_entry.size <<= 10

            f = FileRule("size", ">", "1" + unit, "include")
            self.assertEqual(f.test(self.file_entry), "include")
            f = FileRule("size", "<", "1" + unit, "include")
            self.assertEqual(f.test(self.file_entry), None)
            f = FileRule("size", "eq", "2" + unit, "include")
            self.assertEqual(f.test(self.file_entry), "include")

        # no unit
        self.file_entry.size = 99
        f = FileRule("size", ">", 100, "include")
        self.assertEqual(f.test(self.file_entry), None)
        f = FileRule("size", "<", 100, "include")
        self.assertEqual(f.test(self.file_entry), "include")
示例#16
0
 def test_lt(self):
     for op in ['lt', '<']:
         f1 = FileRule('size', op, 10, 'include')
         f2 = FileRule('size', op, 0, 'include')
         self.assertEqual(f1.test(self.file_entry), 'include')
         self.assertEqual(f2.test(self.file_entry), None)
示例#17
0
 def test_ne(self):
     for op in ["ne", "!=", "<>"]:
         f1 = FileRule("name", op, os.path.basename(self.file_path), "exclude")
         f2 = FileRule("name", op, "...", "exclude")
         self.assertEqual(f2.test(self.file_entry), "exclude")
         self.assertEqual(f1.test(self.file_entry), None)
示例#18
0
 def test_gte(self):
     for op in ["gte", ">="]:
         f1 = FileRule("mtime", op, format_datetime(time() - 3600), "exclude")
         f2 = FileRule("mtime", op, format_datetime(time() + 3600), "exclude")
         self.assertEqual(f1.test(self.file_entry), "exclude")
         self.assertEqual(f2.test(self.file_entry), None)
示例#19
0
 def test_lt(self):
     for op in ["lt", "<"]:
         f1 = FileRule("size", op, 10, "include")
         f2 = FileRule("size", op, 0, "include")
         self.assertEqual(f1.test(self.file_entry), "include")
         self.assertEqual(f2.test(self.file_entry), None)
示例#20
0
    def test_size(self):
        self.file_entry.size = 2
        for unit in ["k", "M", "G"]:

            f = FileRule('size', '>', "1" + unit, 'include')
            self.assertEqual(f.test(self.file_entry), None)
            f = FileRule('size', '<', "1" + unit, 'include')
            self.assertEqual(f.test(self.file_entry), 'include')

            self.file_entry.size <<= 10

            f = FileRule('size', '>', "1" + unit, 'include')
            self.assertEqual(f.test(self.file_entry), 'include')
            f = FileRule('size', '<', "1" + unit, 'include')
            self.assertEqual(f.test(self.file_entry), None)
            f = FileRule('size', 'eq', "2" + unit, 'include')
            self.assertEqual(f.test(self.file_entry), 'include')

        # no unit
        self.file_entry.size = 99
        f = FileRule('size', '>', 100, 'include')
        self.assertEqual(f.test(self.file_entry), None)
        f = FileRule('size', '<', 100, 'include')
        self.assertEqual(f.test(self.file_entry), 'include')
示例#21
0
    def test_size(self):
        self.file_entry.size = 2
        for unit in ["k", "M", "G"]:

            f = FileRule('size', '>', "1"+unit, 'include')
            self.assertEqual(f.test(self.file_entry), None)
            f = FileRule('size', '<', "1"+unit, 'include')
            self.assertEqual(f.test(self.file_entry), 'include')

            self.file_entry.size <<= 10

            f = FileRule('size', '>', "1"+unit, 'include')
            self.assertEqual(f.test(self.file_entry), 'include')
            f = FileRule('size', '<', "1"+unit, 'include')
            self.assertEqual(f.test(self.file_entry), None)
            f = FileRule('size', 'eq', "2"+unit, 'include')
            self.assertEqual(f.test(self.file_entry), 'include')

        # no unit
        self.file_entry.size = 99
        f = FileRule('size', '>', 100, 'include')
        self.assertEqual(f.test(self.file_entry), None)
        f = FileRule('size', '<', 100, 'include')
        self.assertEqual(f.test(self.file_entry), 'include')
示例#22
0
    def test_match(self):
        f1 = FileRule('name', 'match', "*", 'include')
        f2 = FileRule('name', 'match', "", 'include')
        f3 = FileRule('name', 'match',
                      os.path.basename(self.file_entry.pathname), 'include')
        self.assertEqual(f1.test(self.file_entry), 'include')
        self.assertEqual(f2.test(self.file_entry), None)
        self.assertEqual(f3.test(self.file_entry), 'include')

        file_entry = self.file_entry.clone()
        file_entry.pathname = "t.test"
        f = FileRule("name", "match", "*.test", "include")
        self.assertEqual(f.test(file_entry), "include")
        file_entry.pathname = "test"
        self.assertEqual(f.test(file_entry), None)
示例#23
0
 def regexp_invalid(self):
     FileRule('name', 'regexp', "*.txt", 'include')
示例#24
0
 def test_lt(self):
     for op in ['lt', '<']:
         f1 = FileRule('size', op, 10, 'include')
         f2 = FileRule('size', op, 0, 'include')
         self.assertEqual(f1.test(self.file_entry), 'include')
         self.assertEqual(f2.test(self.file_entry), None)