Esempio n. 1
0
    def test_position_case_C(self):
        """UNIT test: services.common.slots.position (CASE C)
        CASE C: slot[0] > interval[0], slot[1] < interval[1]
        """

        i0 = misc.get_next_midnight() + py_delta(days=300, hours=12)
        interval = (i0, i0 + py_delta(days=2))

        slot = (
            misc.get_next_midnight() + py_delta(hours=13),
            misc.get_next_midnight() + py_delta(hours=14)
        )
        result = slots.position(interval, slot)
        expected = (
            slot[0] + py_delta(days=300), slot[1] + py_delta(days=300)
        )

        self.assertEquals(result, expected)

        slot = (
            misc.get_next_midnight() + py_delta(hours=13),
            misc.get_next_midnight() + py_delta(days=1, hours=10)
        )
        result = slots.position(interval, slot)
        expected = (
            slot[0] + py_delta(days=300), slot[1] + py_delta(days=300)
        )

        self.assertEquals(result, expected)
Esempio n. 2
0
 def test_cutoff_case_C(self):
     """UNIT test: services.common.slots.cutoff_slot (CASE C)
     CASE C: slot[0] > interval[0] && slot[1] < interval[1]
     """
     self.assertEquals(
         slots.cutoff((
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         ), (
             misc.get_next_midnight() + py_delta(minutes=15),
             misc.get_next_midnight() + py_delta(minutes=30)
         )), (
             misc.get_next_midnight() + py_delta(minutes=15),
             misc.get_next_midnight() + py_delta(minutes=30)
         )
     )
     self.assertEquals(
         slots.cutoff((
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         ), (
             misc.get_next_midnight() + py_delta(minutes=15),
             misc.get_next_midnight() + py_delta(hours=1)
         )), (
             misc.get_next_midnight() + py_delta(minutes=15),
             misc.get_next_midnight() + py_delta(hours=1)
         )
     )
Esempio n. 3
0
    def test_position_case_A(self):
        """UNIT test: services.common.slots.position (CASE A)
        CASE A: slot[1] < interval[0]
        """

        i0 = misc.get_next_midnight() + py_delta(days=300, hours=12)
        interval = (i0, i0 + py_delta(days=2))

        slot = (misc.get_next_midnight(),
                misc.get_next_midnight() + py_delta(hours=2))
        result = slots.position(interval, slot)
        expected = (slot[0] + py_delta(days=301), slot[1] + py_delta(days=301))

        self.assertEquals(result, expected)
Esempio n. 4
0
 def test_cutoff_case_A(self):
     """UNIT test: services.common.slots.cutoff_slot (CASE A)
     CASE A: slot[1] < interval[0]
     """
     self.assertRaisesMessage(
         ValueError, '@cutoff_slot: slot[1] <= interval[0]',
         slots.cutoff, (
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         ), (
             misc.get_next_midnight() - py_delta(hours=4),
             misc.get_next_midnight() - py_delta(hours=3),
         )
     )
Esempio n. 5
0
 def test_position_none(self):
     """UNIT test: services.common.slots.position (robustness)
     Nones and empties test.
     """
     self.assertRaises(ValueError, slots.position, None, None)
     self.assertRaises(ValueError, slots.position, None, ())
     self.assertRaises(ValueError, slots.position, (), None)
     self.assertRaises(ValueError, slots.position, (), ())
     self.assertRaises(
         ValueError, slots.position, (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         ), ()
     )
     self.assertRaises(
         ValueError, slots.position, (), (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         )
     )
     self.assertRaises(
         ValueError, slots.position, (
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         ), (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         )
     )
     self.assertRaises(
         ValueError, slots.position, (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         ), (
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         )
     )
Esempio n. 6
0
 def test_cutoff_none(self):
     """UNIT test: services.common.slots.cutoff_slot (robustness)
     Nones and empties test.
     """
     self.assertRaises(ValueError, slots.cutoff, None, None)
     self.assertRaises(ValueError, slots.cutoff, None, ())
     self.assertRaises(ValueError, slots.cutoff, (), None)
     self.assertRaises(ValueError, slots.cutoff, (), ())
     self.assertRaises(
         ValueError, slots.cutoff, (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         ), ()
     )
     self.assertRaises(
         ValueError, slots.cutoff, (), (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         )
     )
     self.assertRaises(
         ValueError, slots.cutoff, (
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         ), (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         )
     )
     self.assertRaises(
         ValueError, slots.cutoff, (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight()
         ), (
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         )
     )
Esempio n. 7
0
 def test_cutoff_case_E(self):
     """UNIT test: services.common.slots.cutoff_slot (CASE E)
     CASE E: slot[0] > interval[1]
     """
     self.assertRaisesMessage(
         ValueError, '@cutoff_slot: slot[0] >= interval[1]',
         slots.cutoff, (
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         ), (
             misc.get_next_midnight() + py_delta(hours=4),
             misc.get_next_midnight() + py_delta(hours=5),
         )
     )
     self.assertRaisesMessage(
         ValueError, '@cutoff_slot: slot[0] >= interval[1]',
         slots.cutoff, (
             misc.get_next_midnight(),
             misc.get_next_midnight() + py_delta(hours=1)
         ), (
             misc.get_next_midnight() + py_delta(hours=1),
             misc.get_next_midnight() + py_delta(hours=5),
         )
     )