示例#1
0
 def test_raises_value_error_if_repeat_delay_neither_int_nor_string_type(
         self):
     with pytest.raises(ValueError):
         Sound({"name": "Sound", "files": [], "repeat_delay": 5.6})
     sound = Sound({"name": "Sound", "files": [], "repeat_delay": "42"})
     with pytest.raises(ValueError):
         sound.repeat_delay = 12.5
示例#2
0
 def test_raises_value_error_if_repeat_delay_interval_max_higher_than_min(
         self):
     with pytest.raises(ValueError):
         Sound({"name": "Sound", "files": [], "repeat_delay": "42-24"})
     sound = Sound({"name": "Sound", "files": [], "repeat_delay": "42"})
     with pytest.raises(ValueError):
         sound.repeat_delay = "42-24"
示例#3
0
 def test_sounds_are_created(self, minimal_sound_group_config):
     sound_1_config = {"name": "Some Sound 1", "files": []}
     sound_2_config = {"name": "Some Sound 2", "files": []}
     minimal_sound_group_config["sounds"] = [sound_1_config, sound_2_config]
     sound_group = SoundGroup(minimal_sound_group_config)
     assert len(sound_group.sounds) == 2
     assert sound_group.sounds[0] == Sound(sound_1_config)
     assert sound_group.sounds[1] == Sound(sound_2_config)
示例#4
0
 def test_repeat_delay_single_int(self):
     sound = Sound({"name": "Sound", "files": [], "repeat_delay": 42})
     assert sound._repeat_delay_min == 42
     assert sound._repeat_delay_max == 42
     assert sound.repeat_delay == 42
     sound.repeat_delay = 24
     assert sound._repeat_delay_min == 24
     assert sound._repeat_delay_max == 24
示例#5
0
 def test_not_equal_if_different_repeat_delays(self):
     sound_1 = Sound({
         "name": "Sound",
         "repeat_delay": "1000-2000",
         "files": []
     })
     sound_2 = Sound({"name": "Sound", "files": []})
     assert sound_1 != sound_2
     assert sound_2 != sound_1
示例#6
0
 def test_repeat_delay_interval(self):
     sound = Sound({"name": "Sound", "files": [], "repeat_delay": "24-42"})
     assert sound._repeat_delay_min == 24
     assert sound._repeat_delay_max == 42
     repeat_delay_sample_value = sound.repeat_delay
     assert repeat_delay_sample_value >= 24
     assert repeat_delay_sample_value <= 42
     sound.repeat_delay = "25-43"
     assert sound._repeat_delay_min == 25
     assert sound._repeat_delay_max == 43
示例#7
0
 def test_sort_in_config(self, minimal_sound_group_config):
     name_starts_with_n_config = {
         "name": "Not First In The Alphabet",
         "files": []
     }
     name_starts_with_a_config = {"name": "Alphabet", "files": []}
     minimal_sound_group_config["sort"] = False
     minimal_sound_group_config["sounds"] = [
         name_starts_with_n_config, name_starts_with_a_config
     ]
     sound_group = SoundGroup(minimal_sound_group_config)
     assert sound_group.sounds[0] == Sound(name_starts_with_n_config)
     assert sound_group.sounds[1] == Sound(name_starts_with_a_config)
示例#8
0
 def test_sounds_are_created(self, minimal_sound_config):
     minimal_sound_config["files"] = [
         "some-filename.wav", "other-filename.wav"
     ]
     sound = Sound(minimal_sound_config)
     assert len(sound.files) == 2
     assert sound.files[0] == SoundFile("some-filename.wav")
     assert sound.files[1] == SoundFile("other-filename.wav")
示例#9
0
 def test_repeat_delay_interval_returns_random_value_in_range(
         self, monkeypatch):
     randint_mock = MagicMock(return_value=42)
     monkeypatch.setattr("src.sound.sound.random.randint", randint_mock)
     sound = Sound({"name": "Sound", "files": [], "repeat_delay": "24-42"})
     assert sound.repeat_delay == 42
     randint_mock.assert_called_once_with(sound._repeat_delay_min,
                                          sound._repeat_delay_max)
示例#10
0
 def test_directory_is_none_by_default(self, minimal_sound_config):
     sound = Sound(minimal_sound_config)
     assert sound.directory is None
示例#11
0
 def test_minimal_dict_as_config(self, minimal_sound_config):
     sound = Sound(minimal_sound_config)
     assert sound.name == "Some Name"
     assert len(sound.files) == 0
示例#12
0
 def test_not_equal_if_different_volumes(self):
     sound_1 = Sound({"name": "Sound", "volume": 0.5, "files": []})
     sound_2 = Sound({"name": "Sound", "files": []})
     assert sound_1 != sound_2
     assert sound_2 != sound_1
示例#13
0
 def test_not_equal_if_different_files(self):
     sound_1 = Sound({"name": "Sound", "files": ["unique-filename.wav"]})
     sound_2 = Sound({"name": "Sound", "files": ["some-filename.wav"]})
     assert sound_1 != sound_2
     assert sound_2 != sound_1
示例#14
0
 def test_not_equal_if_different_repeat_counts(self):
     sound_1 = Sound({"name": "Sound", "repeat_count": 2, "files": []})
     sound_2 = Sound({"name": "Sound", "files": []})
     assert sound_1 != sound_2
     assert sound_2 != sound_1
示例#15
0
 def test_repeat_delay_is_zero_by_default(self, minimal_sound_config):
     sound = Sound(minimal_sound_config)
     assert sound.repeat_delay == 0
示例#16
0
 def test_repeat_count_in_config(self, minimal_sound_config):
     minimal_sound_config["repeat_count"] = 42
     sound = Sound(minimal_sound_config)
     assert sound.repeat_count == 42
示例#17
0
 def test_repeat_count_is_one_by_default(self, minimal_sound_config):
     sound = Sound(minimal_sound_config)
     assert sound.repeat_count == 1
示例#18
0
 def test_equal_if_same_config(self):
     sound_1 = Sound({"name": "Sound", "files": []})
     sound_2 = Sound({"name": "Sound", "files": []})
     assert sound_1 == sound_2
     assert sound_2 == sound_1
示例#19
0
 def test_not_equal_if_different_types(self):
     config = {"name": "Sound", "files": []}
     sound = Sound(config)
     assert sound != config
     assert config != sound
示例#20
0
 def test_directory_in_config(self, minimal_sound_config):
     minimal_sound_config["directory"] = "/some/dir/"
     sound = Sound(minimal_sound_config)
     assert sound.directory == "/some/dir/"
示例#21
0
 def test_files_use_tuple_instead_of_list(self, minimal_sound_config):
     sound = Sound(minimal_sound_config)
     assert isinstance(sound.files, tuple)