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)
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)
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)
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)
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)
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)
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')
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)
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")
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)
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')
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")
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)
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)
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)
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)
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')
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')
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)
def regexp_invalid(self): FileRule('name', 'regexp', "*.txt", 'include')