def test_process_met_weekdays(self): """ Test _process_met method when setting weekdays parameter """ m = mox.Mox() m_to_fri = '0-4' p1 = TimeWindow('test', {}, begin=None, end=None, weekdays=m_to_fri, parent=None, interval=0.1) p2 = TimeWindow('test', {}, begin=None, end=None, weekdays=m_to_fri, parent=None, interval=0.1) m.StubOutWithMock(p1, 'weekday') p1.weekday().AndReturn(1) # pretend it's Tuesday m.StubOutWithMock(p2, 'weekday') p2.weekday().AndReturn(6) # pretend it's Sunday m.ReplayAll() p1._process_met() p2._process_met() # should be 'met' if weekdays = mon-fri and it is Tuesday self.assertEqual(p1.met, True) # should not be 'met' if weekdays = mon-fri and it is Sunday self.assertEqual(p2.met, False) m.VerifyAll() m.UnsetStubs()
def test_process_met_end(self): """ Test _process_met method when setting 'end' parameter """ m = mox.Mox() midnight = '00:00:00' one = '01:00:00' p1 = TimeWindow('test', {}, begin=None, end=one, weekdays=None, parent=None, interval=0.1) p2 = TimeWindow('test', {}, begin=None, end=midnight, weekdays=None, parent=None, interval=0.1) mid_time = datetime.datetime.strptime(midnight, '%H:%M:%S').time() one_time = datetime.datetime.strptime(one, '%H:%M:%S').time() m.StubOutWithMock(p1, '_get_comparison') p1._get_comparison(p1.end).AndReturn(mid_time) # pretend it's midnight m.StubOutWithMock(p2, '_get_comparison') p2._get_comparison(p2.end).AndReturn(one_time) # pretend it's one m.ReplayAll() p1._process_met() p2._process_met() # should be 'met' if end is one and it is midnight self.assertEqual(p1.met, True) # should not be 'met' if end is midnight and it is one self.assertEqual(p2.met, False) m.VerifyAll() m.UnsetStubs()
def test_process_met_attributes_all_none(self): """ Test that when all parameters are None 'met' is False """ p = TimeWindow('test', {}, begin=None, end=None, weekdays=None, parent=None, interval=0.1) p._process_met() self.assertEqual(p.met, False)
def test_process_met_attributes_all_none(self): """ Test that when all parameters are None 'met' is False """ p = TimeWindow('test', begin=None, end=None, weekdays=None, parent=None, interval=0.1) p._process_met() self.assertEqual(p.met, False)
def test_process_met_end(self): """ Test _process_met method when setting 'end' parameter """ m = mox.Mox() midnight = '00:00:00' one = '01:00:00' p1 = TimeWindow('test', begin=None, end=one, weekdays=None, parent=None, interval=0.1) p2 = TimeWindow('test', begin=None, end=midnight, weekdays=None, parent=None, interval=0.1) mid_time = datetime.datetime.strptime(midnight, '%H:%M:%S').time() one_time = datetime.datetime.strptime(one, '%H:%M:%S').time() m.StubOutWithMock(p1, '_get_comparison') p1._get_comparison(p1.end).AndReturn(mid_time) # pretend it's midnight m.StubOutWithMock(p2, '_get_comparison') p2._get_comparison(p2.end).AndReturn(one_time) # pretend it's one m.ReplayAll() p1._process_met() p2._process_met() # should be 'met' if end is one and it is midnight self.assertEqual(p1.met, True) # should not be 'met' if end is midnight and it is one self.assertEqual(p2.met, False) m.VerifyAll() m.UnsetStubs()
def test_process_met_weekdays(self): """ Test _process_met method when setting weekdays parameter """ m = mox.Mox() m_to_fri = '0-4' p1 = TimeWindow('test', begin=None, end=None, weekdays=m_to_fri, parent=None, interval=0.1) p2 = TimeWindow('test', begin=None, end=None, weekdays=m_to_fri, parent=None, interval=0.1) m.StubOutWithMock(p1, 'weekday') p1.weekday().AndReturn(1) # pretend it's Tuesday m.StubOutWithMock(p2, 'weekday') p2.weekday().AndReturn(6) # pretend it's Sunday m.ReplayAll() p1._process_met() p2._process_met() # should be 'met' if weekdays = mon-fri and it is Tuesday self.assertEqual(p1.met, True) # should not be 'met' if weekdays = mon-fri and it is Sunday self.assertEqual(p2.met, False) m.VerifyAll() m.UnsetStubs()