def test_eq(self): e1 = Event("a", "b", "c") e2 = Event("a", "b") e3 = Event("x", "y") e4 = Event("x", "y", '') self.assertNotEqual(e1, 'Hello world') self.assertEqual(e3, e4) self.assertNotEqual(e1, e2) self.assertNotEqual(e1, e3) self.assertNotEqual(e2, e3)
def test_from_string(self): s_skip2 = 'a; ; c;' self.assertEqual(Event('a', 'c'), Event.from_string(s_skip2)) s_skip3 = 'a; ; c; d' self.assertEqual(Event('a', 'c', 'd'), Event.from_string(s_skip3)) s = 'a;b;c' self.assertEqual(Event('a', 'b', 'c'), Event.from_string(s)) s_spaces = ' a ; b ; c ' self.assertEqual(Event('a', 'b', 'c'), Event.from_string(s_spaces)) s_empty = 'a; b;;; c ; ; ;' self.assertEqual(Event('a', 'b', 'c'), Event.from_string(s_empty))
def test_from_string(self): self.assertEqual( CronLine(CronTime('*', '*', '*'), Event('hello', 'world')), CronLine.from_string(' * * * hello; world')) self.assertEqual( CronLine.from_string(' * * * hello; world'), CronLine.from_string( ' * * * hello; world #simple example with comment')) self.assertEqual( CronLine(CronTime('1-20,0/25', '0/2', '*'), Event('unit', 'test', 'here')), CronLine.from_string(' 1-20,0/25 0/2 * unit; test ;here')) self.assertEqual(None, CronLine.from_string(' #this is a comment')) self.assertEqual(None, CronLine.from_string(' ')) with self.assertRaises(AttributeError): CronLine.from_string(' * * * ') with self.assertRaises(AttributeError): CronLine.from_string(' 1-20,0/25 * unit; test ;here')
def test_read_lines(self): today = date.today() day = today.day month = today.month weekday = today.weekday() errors = reader.read_lines(TEST_FILE, day, month, weekday).errors self.assertTrue(len(errors) == 1) self.assertTrue(9 in errors) events = reader.read_lines(TEST_FILE, day, month, weekday).events self.assertTrue(len(events) >= 2) self.assertTrue(Event('test', 'event') in events) self.assertTrue(Event('commented', 'event') in events) events = reader.read_lines(TEST_FILE, day, month, 7).events self.assertTrue(len(events) >= 3) self.assertTrue(Event('weekend', 'event') in events) events = reader.read_lines(TEST_FILE, 30, 2, 1).events self.assertTrue(len(events) >= 3) self.assertTrue(Event('impossible', 'event') in events)
def test_from_string_error(self): s_short = 'a' s_empty = 'a; ; ' s_long = 'a; b; c; d' with self.assertRaises(AttributeError): Event.from_string(s_short) with self.assertRaises(AttributeError): Event.from_string(s_empty) with self.assertRaises(AttributeError): Event.from_string(s_long)
def test_to_text(self): e1 = Event("a", "b", "c") e2 = Event("a", "b") self.assertEqual('a:\n\tb\n\tc', e1.to_text()) self.assertEqual('a:\n\tb', e2.to_text())
def test_repr(self): e1 = Event("a", "b", "c") e2 = Event("a", "b") self.assertEqual("Event('a', 'b', 'c')", repr(e1)) self.assertEqual("Event('a', 'b', '')", repr(e2))
def test_str(self): e1 = Event("a", "b", "c") e2 = Event("a", "b") self.assertEqual("a; b; c", str(e1)) self.assertEqual("a; b", str(e2))