Beispiel #1
0
    def test_get(self):
        init_time = self.init_time
        stop_time = self.stop_time
        start_time = self.start_time
        new_init_time = self.new_init_time

        with self.assertRaises(gDIO.KeyError):
            get()

        init(init_time)

        now_time = datetime.datetime(2011, 1, 1, 0, 0, 0, 0)
        with self.assertRaises(gDIO.CalcSpaceError):
            get(now_time)

        now_time = datetime.datetime(2012, 1, 1, 1, 0, 0, 0)
        expr_seconds = _new()._delta_to_sec(now_time - init_time)
        seconds = get(now_time)
        self.assertEqual(seconds, expr_seconds)

        stop(stop_time)
        now_time = datetime.datetime(2013, 1, 1, 0, 0, 0, 0)
        expr_seconds = _new()._delta_to_sec(stop_time - init_time)
        seconds = get(now_time)
        self.assertEqual(seconds, expr_seconds)

        start(start_time)
        expr_seconds = _new()._delta_to_sec(now_time - new_init_time)
        seconds = get(now_time)
        self.assertEqual(seconds, expr_seconds)
Beispiel #2
0
    def test_start(self):
        dio = self.dio
        init_time = self.init_time
        stop_time = self.stop_time
        start_time = self.start_time
        new_init_time = self.new_init_time

        with self.assertRaises(gDIO.KeyError):
            start()

        init(init_time)

        with self.assertRaises(gDIO.KeyError):
            start()

        stop(stop_time)
        start(start_time)
        self.assertIsNone(dio._r.get(dio._stop_key()))
        self._assertTime(dio._init_key(), new_init_time)
Beispiel #3
0
    def test_stop(self):
        dio = self.dio
        stop_time = self.stop_time

        stop(stop_time)
        self._assertTime(dio._stop_key(), stop_time)