def test_should_handle_intervals_shorter_than_the_progress_period(self): l = testhelper.Listener() self._runner.connect('event', l.call) self._runner.PROGRESS_PERIOD = 10.0 self._runner.start() self._runner.join() testhelper.assert_close(l.elapsed(beeps.helpers.event.RoutineStarted, beeps.helpers.event.RoutineFinished), self._runner.routine.time())
def test_should_handle_on_volume_increase_activate(self): volumebutton = testhelper.find_child(self._controller.view, 'volumebutton') testhelper.assert_close(volumebutton.get_value(), 0.1) self._setup_callback(self._controller.view.lookup_action('volume::increase').activate) self._setup_callback(self._do_close_window) gi.repository.Gtk.main() testhelper.assert_close(volumebutton.get_value(), 0.3)
def test_should_be_able_to_seek_in_a_routine(self): self._runner.seek(0.5) p = 0.5 / self._runner.routine.time() testhelper.assert_close(self._runner.routine.progress(), p) self._runner.start() self._runner.stop() assert(self._runner.routine.progress() > p)
def test_should_handle_on_control_seek_change_value(self): self._create_routine(2) testhelper.assert_close(self._plan.routines[-1].completed(), 0.0) seekscale = testhelper.find_child(self._controller.view, 'seekscale') self._setup_callback(seekscale.emit, 'change-value', gi.repository.Gtk.ScrollType.JUMP, 50.0) self._setup_callback(self._do_close_window) gi.repository.Gtk.main() testhelper.assert_close(self._plan.routines[-1].completed(), 1.0)
def test_should_handle_interval_progressed(self): testhelper.Events.interval_created(self._view, self._plan) testhelper.Events.interval_progressed(self._view, self._plan) testhelper.assert_close(self._view.get_value(), 0.0) self._plan.runner.start() self._plan.runner.join() testhelper.Events.interval_progressed(self._view, self._plan) testhelper.assert_close(self._view.get_value(), 100.0)
def test_should_provide_the_completed_time(self): testhelper.assert_close(self._interval.completed(), 0.0) self._interval.start() t = self._interval.completed() assert(t > 0.0) assert(t < 1.0) self._interval.start() time.sleep(2) self._interval.stop() testhelper.assert_close(self._interval.completed(), 1.0)
def test_should_provide_the_remaining_time(self): assert(self._interval.remaining() >= 1.0) self._interval.start() t = self._interval.remaining() assert(t > 0.0) assert(t < 1.0) self._interval.start() time.sleep(2) self._interval.stop() testhelper.assert_close(self._interval.remaining(), 0.0)
def test_should_be_able_to_seek_in_a_routine_that_is_in_progress(self): l = testhelper.Listener() self._controller.model.runner.connect('event', l.call) d = 100 self._create_routine(d) seekscale = testhelper.find_child(self._controller.view, 'seekscale') self._setup_callback(self._controller.view.lookup_action('control::startstop').activate) self._setup_callback(seekscale.emit, 'change-value', gi.repository.Gtk.ScrollType.JUMP, 33.0) self._setup_callback(self._do_close_window) gi.repository.Gtk.main() assert(0 < l.elapsed(beeps.helpers.event.RoutineStarted, beeps.helpers.event.IntervalProgressed) < d) testhelper.assert_close(self._plan.runner.routine.progress(), 0.33)
def test_should_be_able_to_seek_to_a_specified_time(self): s = 0.25 self._interval.seek(s) c1 = self._interval.completed() testhelper.assert_close(c1, s) self._interval.start() self._interval.stop() c2 = self._interval.completed() assert(c2 > c1) self._interval.start() self._interval.stop() c3 = self._interval.completed() assert(c3 > c2)
def test_should_be_updateable(self): interval = beeps.models.plan.AudibleInterval(10) assert(interval.sound == None) t = 10.0 s = '/' interval.update(time = t, sound = s) testhelper.assert_close(interval.time, t) assert(interval.sound == s) interval.update(time = t) assert(interval.sound == s) interval.update(time = t, sound = None) assert(interval.sound == None) interval.update(time = t, sound = t) assert(interval.sound == None)
def test_should_be_updateable(self): s = 0.25 self._interval.seek(s) c1 = self._interval.completed() testhelper.assert_close(c1, s) testhelper.assert_close(self._interval.time, 1.0) t = 10.0 self._interval.update(time = t) c2 = self._interval.completed() testhelper.assert_close(c2, 0.0) testhelper.assert_close(self._interval.time, t)
def test_should_handle_one_interval_seeking_backward(self): self._routine.create_interval(5) self._routine.seek(self._routine.time()) testhelper.assert_range(range(0, 1), self._seek(2.5)) testhelper.assert_close(self._routine.intervals[0].completed(), 2.5) testhelper.assert_range(range(0, 1), self._seek(0.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 0.0) testhelper.assert_range(range(0, 0), self._seek(-5.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 0.0)
def test_should_provide_the_current_volume(self): testhelper.assert_close(self._view.get_value(), 0.1)
def test_should_handle_routine_unloaded(self): testhelper.Events.routine_loaded(self._view, self._plan) testhelper.Events.interval_created(self._view, self._plan) self._view.set_value(50.0) testhelper.Events.routine_unloaded(self._view, self._plan) testhelper.assert_close(self._view.get_value(), 0.0)
def test_should_handle_routine_loaded(self): testhelper.Events.routine_loaded(self._view, self._plan) testhelper.assert_close(self._view.get_value(), 0.0)
def test_should_handle_interval_updated(self): testhelper.Events.interval_created(self._view, self._plan, {'time' : 1.5}) testhelper.Events.interval_updated(self._view, self._plan, {'time' : 2.0}) testhelper.assert_close(self._view.get_value(), 0.0)
def test_should_support_decoding_from_json(self): data = json.loads('{"time":"1.0","sound":"/"}') interval = beeps.models.plan.AudibleInterval.from_json(data) assert(interval.sound == '/') testhelper.assert_close(interval.time, 1.0)
def test_assert_close(): testhelper.assert_close(1.1, 1.0, 0.2) testhelper.assert_close(1.0, 1.1, 0.2) testhelper.assert_close(0.0, 0.1, 1.0) testhelper.assert_close(0.1, 0.0, 1.0) with pytest.raises(AssertionError): testhelper.assert_close(1.0, 0.9, 0.099) with pytest.raises(AssertionError): testhelper.assert_close(0.9, 1.0, 0.099) with pytest.raises(AssertionError): testhelper.assert_close(0.1, 0.0, 0.99) with pytest.raises(AssertionError): testhelper.assert_close(0.0, 0.1, 0.99)
def _do_control_restart_toggled(self): testhelper.assert_close(self._controller.model.routines[-1].completed(), 0.5) self._controller.view.lookup_action('control::restart').activate() testhelper.assert_close(self._controller.model.routines[-1].completed(), 0.0) self._do_close_window()
def test_should_have_a_length_of_zero_by_default(self): testhelper.assert_close(self._routine.time(), 0.0)
def test_should_handle_one_interval_seeking_forward(self): self._routine.create_interval(5) testhelper.assert_range(range(0, 1), self._seek(2.5)) testhelper.assert_close(self._routine.intervals[0].completed(), 2.5) testhelper.assert_range(range(0, 1), self._seek(10.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 5.0)
def test_should_handle_two_intervals_jump_seeking_forward(self): self._routine.create_interval(5) self._routine.create_interval(10) self._routine.seek(15) for i in range(0, 2): testhelper.assert_close(self._routine.intervals[i].completed(), self._routine.intervals[i].time)
def test_should_handle_two_intervals_seeking_backward(self): self._routine.create_interval(5) self._routine.create_interval(10) self._routine.seek(15) testhelper.assert_range(range(1, 2), self._seek(10.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 5.0) testhelper.assert_close(self._routine.intervals[1].completed(), 5.0) testhelper.assert_range(range(1, 2), self._seek(5.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 5.0) testhelper.assert_close(self._routine.intervals[1].completed(), 0.0) testhelper.assert_range(range(0, 1), self._seek(2.5)) testhelper.assert_close(self._routine.intervals[0].completed(), 2.5) testhelper.assert_close(self._routine.intervals[1].completed(), 0.0) testhelper.assert_range(range(0, 0), self._seek(2.5)) testhelper.assert_close(self._routine.intervals[0].completed(), 2.5) testhelper.assert_close(self._routine.intervals[1].completed(), 0.0) testhelper.assert_range(range(0, 1), self._seek(0.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 0.0) testhelper.assert_close(self._routine.intervals[1].completed(), 0.0) testhelper.assert_range(range(0, 0), self._seek(0.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 0.0) testhelper.assert_close(self._routine.intervals[1].completed(), 0.0)
def test_should_handle_many_intervals_seeking_backward(self): self._routine.create_interval(5) # 5 self._routine.create_interval(10) # 15 self._routine.create_interval(15) # 30 self._routine.create_interval(10) # 40 self._routine.create_interval(5) # 45 self._routine.seek(self._routine.time()) testhelper.assert_range(range(5, 5), self._seek(self._routine.time())) for i in range(0, 5): testhelper.assert_close(self._routine.intervals[i].completed(), self._routine.intervals[i].time) testhelper.assert_range(range(4, 4), self._seek(35.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 5.0) testhelper.assert_close(self._routine.intervals[1].completed(), 10.0) testhelper.assert_close(self._routine.intervals[2].completed(), 15.0) testhelper.assert_close(self._routine.intervals[3].completed(), 5.0) testhelper.assert_close(self._routine.intervals[4].completed(), 0.0) testhelper.assert_range(range(3, 4), self._seek(30.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 5.0) testhelper.assert_close(self._routine.intervals[1].completed(), 10.0) testhelper.assert_close(self._routine.intervals[2].completed(), 15.0) testhelper.assert_close(self._routine.intervals[3].completed(), 0.0) testhelper.assert_close(self._routine.intervals[4].completed(), 0.0) testhelper.assert_range(range(2, 3), self._seek(20.0)) testhelper.assert_close(self._routine.intervals[0].completed(), 5.0) testhelper.assert_close(self._routine.intervals[1].completed(), 10.0) testhelper.assert_close(self._routine.intervals[2].completed(), 5.0) testhelper.assert_close(self._routine.intervals[3].completed(), 0.0) testhelper.assert_close(self._routine.intervals[4].completed(), 0.0) testhelper.assert_range(range(2, 1), self._seek(-100.0)) for i in range(0, 5): testhelper.assert_close(self._routine.intervals[i].completed(), 0.0) testhelper.assert_range(range(0, 0), self._seek(-100.0))
def test_should_provide_the_completed_percent(self): testhelper.assert_close(self._routine.progress(), 0.0) self._routine.create_interval(1.0) self._routine.seek(0.75) testhelper.assert_close(self._routine.progress(), 0.75)
def test_should_be_possible_to_restart_a_routine(self): self._runner.start() self._runner.join() testhelper.assert_close(self._runner.routine.progress(), 1.0) self._runner.seek(0.0) testhelper.assert_close(self._runner.routine.progress(), 0.0)