Exemplo n.º 1
0
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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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]
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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]]
Exemplo n.º 9
0
 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'})
Exemplo n.º 10
0
 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]]
Exemplo n.º 11
0
 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')
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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')
Exemplo n.º 14
0
    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])
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
    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]])
Exemplo n.º 17
0
 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]])
Exemplo n.º 18
0
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
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
 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)
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
 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)
Exemplo n.º 23
0
    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")
Exemplo n.º 24
0
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"
Exemplo n.º 25
0
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]]
Exemplo n.º 26
0
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
Exemplo n.º 27
0
    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")
Exemplo n.º 28
0
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"
Exemplo n.º 29
0
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
Exemplo n.º 30
0
 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)