Esempio n. 1
0
 def test_set(self):
     entry = TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0))
     assert entry.state == 0
     assert entry.period == TimeProgPeriod(0, 0, 0, 0)
     state = 123
     period = TimeProgPeriod(21, 22, 23, 24)
     entry.set(state, period)
     assert entry.state == state
     assert entry.period == period
     assert entry.period is not period  # entry.period should be a "deepcopy" of period
Esempio n. 2
0
 def test_properties(self):
     state = 0
     period = TimeProgPeriod(0, 0, 0, 0)
     entry = TimeProgEntry(state, period)
     assert entry.state == state
     assert entry.period == period
     assert entry.period is not period  # entry.period should be a "deepcopy" of period
     entry.state = 123
     assert entry.state == 123
     period = TimeProgPeriod(21, 22, 23, 24)
     entry.period = period
     assert entry.period == period
     assert entry.period is not period  # entry.period should be a "deepcopy" of period
Esempio n. 3
0
 def test_set_entry_raises_IndexError(self):
     time_prog = TimeProgram(0, "Name", 10, 3, 15, 7)
     entry = TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0))
     with pytest.raises(IndexError):
         time_prog.set_entry(time_prog.number_of_days, 0, entry)
     with pytest.raises(IndexError):
         time_prog.set_entry(0, time_prog.entries_a_day, entry)
Esempio n. 4
0
 def test_entry(self, day: int, num: int):
     time_prog = TimeProgram(0, "Name", 10, 3, 10, 7)
     assert time_prog.entry(day, num) is None
     entry = TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0))
     time_prog.set_entry(day, num, entry)
     assert time_prog.entry(day, num) == entry
     assert time_prog.entry(day, num) is not entry  # time_prog.entry() should be a "deepcopy" of entry
Esempio n. 5
0
 def test_str(self):
     time_prog = TimeProgram(0, "Name", 10, 3, 10, 7)
     assert str(time_prog) ==\
         "idx={:d}, name={!r}, ead={:d}, nos={:d}, ste={:d}, nod={:d}, entries=[{}]".format(
             0, "Name", 10, 3, 10, 7, "")
     time_prog.set_entry(0, 0, TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)))
     assert str(time_prog) ==\
         "idx={:d}, name={!r}, ead={:d}, nos={:d}, ste={:d}, nod={:d}, entries=[{}]".format(
             0, "Name", 10, 3, 10, 7, "...")
Esempio n. 6
0
 def test_set_entry_raises_ValueError(self, state: int,
                                      start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     time_prog = TimeProgram(0, "Name", 10, 3, 15, 7)
     period = TimeProgPeriod(start_hour, start_minute, end_hour, end_minute)
     with pytest.raises(ValueError):
         time_prog.set_entry(0, 0, TimeProgEntry(state, period))
Esempio n. 7
0
 def test_as_json(self):
     state = 123
     period = TimeProgPeriod(21, 22, 23, 24)
     assert TimeProgEntry(state, period).as_json() ==\
         {"state": state, "start": period.start_str, "end": period.end_str}
Esempio n. 8
0
 def test_as_dict(self):
     state = 123
     period = TimeProgPeriod(21, 22, 23, 24)
     assert TimeProgEntry(state, period).as_dict() == {"state": state, "start": period.start, "end": period.end}
Esempio n. 9
0
 def test_eq(self):
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != None  # noqa: E711
     with pytest.raises(TypeError):
         TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != 123
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) == TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(1, TimeProgPeriod(0, 0, 0, 0))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 1))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(0, TimeProgPeriod(0, 0, 1, 0))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(0, TimeProgPeriod(0, 1, 0, 1))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(0, TimeProgPeriod(1, 0, 1, 0))
Esempio n. 10
0
 def test_str(self, state: str):
     assert str(TimeProgEntry.from_str(str(state), "00:00", "00:00")) ==\
         "state={:d}, time={!s}".format(state, TimeProgPeriod.from_str("00:00", "00:00"))
Esempio n. 11
0
 def test_from_str(self, state: str):
     entry = TimeProgEntry.from_str(str(state), "00:00", "00:00")
     assert entry.state == state
Esempio n. 12
0
 def test_from_str_raises_ValueError(self, state: str):
     with pytest.raises(ValueError):
         TimeProgEntry.from_str(state, "00:00", "00:00")