Exemplo 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
Exemplo 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
Exemplo n.º 3
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),
         }
Exemplo n.º 4
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),
                           }
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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,
     }
Exemplo n.º 8
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
Exemplo n.º 9
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,
     }
Exemplo n.º 10
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, "...")
Exemplo n.º 11
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))
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def test_from_json(self):
     time_prog = TimeProgram.from_json({
         "index": 0,
         "name": "Name",
         "ead": 10,
         "nos": 3,
         "ste": 10,
         "nod": 7
     })
     assert time_prog.index == 0
     assert time_prog.name == "Name"
     assert time_prog.entries_a_day == 10
     assert time_prog.number_of_states == 3
     assert time_prog.step_size == 10
     assert time_prog.number_of_days == 7
     assert len(time_prog._entries) == time_prog.number_of_days
     assert all([
         len(entries_of_day) == time_prog.entries_a_day
         for entries_of_day in time_prog._entries
     ])
     time_prog = TimeProgram.from_json({
         "index":
         0,
         "name":
         "Name",
         "ead":
         10,
         "nos":
         3,
         "ste":
         10,
         "nod":
         7,
         "entries": [[None for _ in range(time_prog.entries_a_day)]
                     for _ in range(time_prog.number_of_days)],
     })
     assert len(time_prog._entries) == time_prog.number_of_days
     assert all([
         len(entries_of_day) == time_prog.entries_a_day
         for entries_of_day in time_prog._entries
     ])
     assert all(
         time_prog.entry(day, num) is None
         for num in range(time_prog.entries_a_day)
         for day in range(time_prog.number_of_days))
     time_prog = TimeProgram.from_json({
         "index":
         0,
         "name":
         "Name",
         "ead":
         10,
         "nos":
         3,
         "ste":
         10,
         "nod":
         7,
         "entries": [[{
             "state": 1,
             "start": "00:00",
             "end": "23:50"
         } for _ in range(time_prog.entries_a_day)]
                     for _ in range(time_prog.number_of_days)],
     })
     assert len(time_prog._entries) == time_prog.number_of_days
     assert all([
         len(entries_of_day) == time_prog.entries_a_day
         for entries_of_day in time_prog._entries
     ])
     assert all(
         time_prog.entry(day, num) == TimeProgEntry(
             1, TimeProgPeriod(0, 0, 23, 50))
         for num in range(time_prog.entries_a_day)
         for day in range(time_prog.number_of_days))
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
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))
Exemplo n.º 20
0
 def test_str(self, state: int):
     assert str(TimeProgEntry.from_str(
         str(state), "00:00", "00:00")) == "state={:d}, time={!s}".format(
             state, TimeProgPeriod.from_str("00:00", "00:00"))
Exemplo n.º 21
0
 def test_from_str(self, start_str: str, end_str: str):
     TimeProgPeriod.from_str(start_str, end_str)
Exemplo n.º 22
0
 def test_from_json(self, json_dict: Dict[str, str]):
     TimeProgPeriod.from_json(json_dict)