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_properties(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     period = TimeProgPeriod(start_hour, start_minute, end_hour, end_minute)
     assert period.start_str == "{:02d}:{:02d}".format(start_hour, start_minute)
     assert period.end_str == "{:02d}:{:02d}".format(end_hour, end_minute)
     assert period.start_hour == start_hour
     assert period.start_minute == start_minute
     assert period.end_hour == end_hour
     assert period.end_minute == end_minute
     assert period.start == (start_hour, start_minute)
     assert period.end == (end_hour, end_minute)
Esempio n. 7
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. 8
0
 def test_init_raises_ValueError(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     with pytest.raises(ValueError):
         TimeProgPeriod(start_hour, start_minute, end_hour, end_minute)
Esempio n. 9
0
 def test_str(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     assert str(TimeProgPeriod(start_hour, start_minute, end_hour, end_minute)) ==\
         "{:02d}:{:02d}-{:02d}:{:02d}".format(start_hour, start_minute, end_hour, end_minute)
Esempio n. 10
0
 def test_from_str(self, start_str: str, end_str: str):
     TimeProgPeriod.from_str(start_str, end_str)
Esempio n. 11
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. 12
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. 13
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. 14
0
 def test_as_json(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     assert TimeProgPeriod(start_hour, start_minute, end_hour, end_minute).as_json() ==\
         {"start": "{:02d}:{:02d}".format(start_hour, start_minute),
          "end": "{:02d}:{:02d}".format(end_hour, end_minute),
          }
Esempio n. 15
0
 def test_as_dict(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     assert TimeProgPeriod(start_hour, start_minute, end_hour, end_minute).as_dict() ==\
         {"start": (start_hour, start_minute), "end": (end_hour, end_minute)}
Esempio n. 16
0
 def test_init(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     TimeProgPeriod(start_hour, start_minute, end_hour, end_minute)
Esempio n. 17
0
 def test_from_str_raises_ValueError(self, start_str: str, end_str: str):
     with pytest.raises(ValueError):
         TimeProgPeriod.from_str(start_str, end_str)
Esempio n. 18
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. 19
0
 def test_set_raises_ValueError(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     period = TimeProgPeriod(0, 0, 0, 0)
     with pytest.raises(ValueError):
         period.set(start_hour, start_minute, end_hour, end_minute)
Esempio n. 20
0
 def test_set(self, start_hour: int, start_minute: int, end_hour: int, end_minute: int):
     TimeProgPeriod(0, 0, 0, 0).set(start_hour, start_minute, end_hour, end_minute)