def test_yearly_working_days_is_calculated_correctly(): """testing if the yearly_working_days is calculated correctly """ wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [] wh['sun'] = [] assert wh.yearly_working_days == pytest.approx(261) wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [] assert wh.yearly_working_days == pytest.approx(313) wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [[13, 14]] assert wh.yearly_working_days == pytest.approx(365)
def test_yearly_working_days_is_calculated_correctly(self): """testing if the yearly_working_days is calculated correctly """ wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [] wh['sun'] = [] self.assertAlmostEqual(wh.yearly_working_days, 261, 3) wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [] self.assertAlmostEqual(wh.yearly_working_days, 313, 4) wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [[13, 14]] self.assertAlmostEqual(wh.yearly_working_days, 365, 0)
def test_weekly_working_days_is_calculated_correctly(self): """testing if the weekly working days are calculated correctly """ wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [] wh['sun'] = [] self.assertEqual(wh.weekly_working_days, 5) wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [] self.assertEqual(wh.weekly_working_days, 6) wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [[13, 14]] self.assertEqual(wh.weekly_working_days, 7)
def test_weekly_working_days_is_calculated_correctly(): """testing if the weekly working days are calculated correctly """ wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [] wh['sun'] = [] assert wh.weekly_working_days == 5 wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [] assert wh.weekly_working_days == 6 wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [[13, 14]] assert wh.weekly_working_days == 7
def test_day_numbers_are_correct(): """testing if the day numbers are correct """ wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [[13, 14]] from stalker import defaults assert defaults.day_order[0] == 'mon' assert defaults.day_order[1] == 'tue' assert defaults.day_order[2] == 'wed' assert defaults.day_order[3] == 'thu' assert defaults.day_order[4] == 'fri' assert defaults.day_order[5] == 'sat' assert defaults.day_order[6] == 'sun' assert wh['mon'] == wh[0] assert wh['tue'] == wh[1] assert wh['wed'] == wh[2] assert wh['thu'] == wh[3] assert wh['fri'] == wh[4] assert wh['sat'] == wh[5] assert wh['sun'] == wh[6]
def test_working_hours_argument_is_None(): """testing if a WorkingHours is created with the default settings if the working_hours argument is None """ wh = WorkingHours(working_hours=None) from stalker import defaults assert wh.working_hours == defaults.working_hours
def test_working_hours_argument_is_skipped(): """testing if a WorkingHours is created with the default settings by default. """ wh = WorkingHours() from stalker import defaults assert wh.working_hours == defaults.working_hours
def test_working_hours_can_be_indexed_with_day_number(): """testing if the working hours for a day can be reached by an index """ wh = WorkingHours() from stalker import defaults assert wh[6] == defaults.working_hours['sun'] wh[6] = [[540, 1080]]
def test_working_hours_attribute_is_set_to_a_dictionary_of_other_formatted_data(self): """testing if a TypeError will be raised when the working hours attribute value is a dictionary of some other value """ wh = WorkingHours() self.assertRaises(TypeError, setattr, wh, 'working_hours', {'not': 'properly valued'})
def test_working_hours_can_be_string_indexed_with_the_date_short_name(self): """testing if the working hours information can be reached by using the short date name as the index """ wh = WorkingHours() self.assertEqual(wh['sun'], defaults.working_hours['sun']) wh['sun'] = [[540, 1080]]
def test_working_hours_attribute_is_not_a_dictionary(self): """testing if a TypeError will be raised when the working_hours attribute is set to a value which is not a dictionary """ wh = WorkingHours() self.assertRaises(TypeError, setattr, wh, 'working_hours', 'not a dictionary of proper values')
def test_working_hours_argument_is_skipped(self): """testing if a WorkingHours is created with the default settings by default. """ wh = WorkingHours() from stalker import defaults self.assertEqual(wh.working_hours, defaults.working_hours)
def test_daily_working_hours_attribute_is_not_an_integer(self): """testing if a TypeError will be raised when the daily_working hours attribute is set to a value other than an integer """ wh = WorkingHours() self.assertRaises(TypeError, setattr, wh, 'daily_working_hours', 'not an integer')
def test_day_numbers_are_correct(self): """testing if the day numbers are correct """ wh = WorkingHours() wh['mon'] = [[1, 2]] wh['tue'] = [[3, 4]] wh['wed'] = [[5, 6]] wh['thu'] = [[7, 8]] wh['fri'] = [[9, 10]] wh['sat'] = [[11, 12]] wh['sun'] = [[13, 14]] self.assertEqual(defaults.day_order[0], 'mon') self.assertEqual(defaults.day_order[1], 'tue') self.assertEqual(defaults.day_order[2], 'wed') self.assertEqual(defaults.day_order[3], 'thu') self.assertEqual(defaults.day_order[4], 'fri') self.assertEqual(defaults.day_order[5], 'sat') self.assertEqual(defaults.day_order[6], 'sun') self.assertEqual(wh['mon'], wh[0]) self.assertEqual(wh['tue'], wh[1]) self.assertEqual(wh['wed'], wh[2]) self.assertEqual(wh['thu'], wh[3]) self.assertEqual(wh['fri'], wh[4]) self.assertEqual(wh['sat'], wh[5]) self.assertEqual(wh['sun'], wh[6])
def test_daily_working_hours_attribute_is_None(self): """testing if the daily_working_hours attribute will be equal to the default settings value when it is set to None """ wh = WorkingHours() wh.daily_working_hours = None self.assertEqual(wh.daily_working_hours, defaults.daily_working_hours)
def test___setitem__checks_the_given_data(self): """testing if the __setitem__ checks the given data format """ wh = WorkingHours() self.assertRaises(TypeError, wh.__setitem__, 0, 'not a proper data') self.assertRaises(TypeError, wh.__setitem__, 'sun', 'not a proper data') self.assertRaises(TypeError, wh.__setitem__, 0, ['no proper data']) self.assertRaises(TypeError, wh.__setitem__, 'sun', ['no proper data']) self.assertRaises(RuntimeError, wh.__setitem__, 0, [['no proper data']]) self.assertRaises(RuntimeError, wh.__setitem__, 'sun', [['no proper data']]) self.assertRaises(RuntimeError, wh.__setitem__, 0, [[3]]) self.assertRaises(TypeError, wh.__setitem__, 2, [[2, 'a']]) self.assertRaises(TypeError, wh.__setitem__, 1, [[20, 10], ['a', 300]]) self.assertRaises(TypeError, wh.__setitem__, 5, [[323, 1344], [2, 'd']]) self.assertRaises(RuntimeError, wh.__setitem__, 0, [[4, 100, 3]]) self.assertRaises(RuntimeError, wh.__setitem__, 'mon', [[3]]) self.assertRaises(TypeError, wh.__setitem__, 'mon', [[2, 'a']]) self.assertRaises(TypeError, wh.__setitem__, 'tue', [[20, 10], ['a', 300]]) self.assertRaises(TypeError, wh.__setitem__, 'fri', [[323, 1344], [2, 'd']]) self.assertRaises(RuntimeError, wh.__setitem__, 'sat', [[4, 100, 3]])
def test___setitem__checks_the_value_ranges(self): """testing if a ValueError will be raised if value is not in the correct range in __setitem__ """ wh = WorkingHours() self.assertRaises(ValueError, wh.__setitem__, 'sun', [[-10, 100]]) self.assertRaises(ValueError, wh.__setitem__, 'sat', [[0, 1800]])
def test_daily_working_hours_argument_is_skipped(): """testing if the daily_working_hours attribute will be equal to the default settings when the daily_working_hours argument is skipped """ wh = WorkingHours() from stalker import defaults assert wh.daily_working_hours == defaults.daily_working_hours
def test_daily_working_hours_attribute_is_set_to_a_number_bigger_than_24( self): """testing if a ValueError will be raised when the daily working hours attribute value is bigger than 24 """ wh = WorkingHours() self.assertRaises(ValueError, setattr, wh, 'daily_working_hours', 25)
def test_yearly_working_days_is_a_read_only_attribute(self): """testing if the yearly_working_days attribute is a read only attribute """ wh = WorkingHours() self.assertRaises(AttributeError, setattr, wh, 'yearly_working_days', 260.1)
def test_daily_working_hours_argument_is_working_fine(self): """testing if the daily working hours argument value is correctly passed to daily_working_hours attribute """ kwargs = dict() kwargs['daily_working_hours'] = 12 wh = WorkingHours(**kwargs) self.assertEqual(wh.daily_working_hours, 12)
def test_daily_working_hours_argument_is_None(self): """testing if the daily_working_hours attribute will be equal to the default settings value when the daily_working_hours argument is None """ kwargs = dict() kwargs['daily_working_hours'] = None wh = WorkingHours(**kwargs) self.assertEqual(wh.daily_working_hours, defaults.daily_working_hours)
def test_weekly_working_days_is_a_read_only_attribute(self): """testing if the weekly working days is a read-only attribute """ wh = WorkingHours() with self.assertRaises(AttributeError) as cm: wh.weekly_working_days = 6 self.assertEqual(str(cm.exception), "can't set attribute")
def test_to_tjp_attribute_is_read_only(): """testing if the to_tjp attribute is read only """ wh = WorkingHours() with pytest.raises(AttributeError) as cm: wh.to_tjp = 'some value' assert str(cm.value) == "can't set attribute"
def test_working_hours_can_be_string_indexed_with_the_date_short_name(): """testing if the working hours information can be reached by using the short date name as the index """ wh = WorkingHours() from stalker import defaults assert wh['sun'] == defaults.working_hours['sun'] wh['sun'] = [[540, 1080]]
def test_daily_working_hours_attribute_is_None(): """testing if the daily_working_hours attribute will be equal to the default settings value when it is set to None """ wh = WorkingHours() wh.daily_working_hours = None from stalker import defaults assert wh.daily_working_hours == defaults.daily_working_hours
def test_to_tjp_attribute_is_read_only(self): """testing if the to_tjp attribute is read only """ wh = WorkingHours() with self.assertRaises(AttributeError) as cm: wh.to_tjp = 'some value' self.assertEqual(str(cm.exception), "can't set attribute")
def test_weekly_working_days_is_a_read_only_attribute(): """testing if the weekly working days is a read-only attribute """ wh = WorkingHours() with pytest.raises(AttributeError) as cm: wh.weekly_working_days = 6 assert str(cm.value) == "can't set attribute"
def test_daily_working_hours_argument_is_None(): """testing if the daily_working_hours attribute will be equal to the default settings value when the daily_working_hours argument is None """ kwargs = dict() kwargs['daily_working_hours'] = None wh = WorkingHours(**kwargs) from stalker import defaults assert wh.daily_working_hours == defaults.daily_working_hours
def test_split_in_to_working_hours_is_not_implemented_yet(self): """testing if a NotimplementedError will be raised when the split_in_to_working_hours() method is called """ with self.assertRaises(NotImplementedError): wh = WorkingHours() start = datetime.datetime.now() end = start + datetime.timedelta(days=10) wh.split_in_to_working_hours(start, end)