def test_sound_selector_widget_set_sound(): """Tests the :class:`~_clockalarm.UI.SoundSelectorWidget.set_sound` method.""" ss_widget = SoundSelectorWidget("mySound.wav") ss_widget.set_sound("new_sound.wav") assert ss_widget.sound_name == "new_sound.wav" assert ss_widget.sound_edit.text() == "new_sound.wav"
def init_ui(self, alert): """Initialization helper method. Attributes: alert: The :class:`~_clockalarm.SimpleAlert` to edit """ group_box = QGroupBox(self) group_box.setTitle('Set up a new Simple Alert') date_time = time.time() + 15 self.periodicity_edit = QTimeEdit() self.periodicity_edit.setDisplayFormat("HH:mm:ss") self.date_time_edit = QDateTimeEdit( QDateTime.fromSecsSinceEpoch(date_time)) self.alert_message_edit = QLineEdit() self.font_family_edit = QLineEdit() self.font_size_edit = QSpinBox() self.font_size_edit.setMaximum(64) self.font_size_edit.setSingleStep(2) self.color_edit = ColorSelectorWidget() self.sound_edit = SoundSelectorWidget() self.accept_button = QPushButton('Validate') if alert: group_box.setTitle('Edit a Simple Alert') self.alert_message_edit.setText( alert.get_notification().get_message()) self.date_time_edit.setDateTime( QDateTime.fromSecsSinceEpoch(alert.trigger_time)) if alert.periodicity is not None: self.periodicity_edit.setTime( QTime(0, 0).addSecs(alert.periodicity)) if alert.notification.font_family is not None: self.font_family_edit.setText(alert.notification.font_family) if alert.notification.font_size is not None: self.font_size_edit.setValue(alert.notification.font_size) if alert.notification.color_hex is not None: self.color_edit.set_hex_color(alert.notification.color_hex) if alert.notification.sound is not None: self.sound_edit.set_sound(alert.notification.sound) grid_layout = QGridLayout(group_box) grid_layout.addWidget(QLabel('Message'), 1, 1) grid_layout.addWidget(self.alert_message_edit, 1, 2) grid_layout.addWidget(QLabel('Date and Time'), 2, 1) grid_layout.addWidget(self.date_time_edit, 2, 2) grid_layout.addWidget(QLabel('Periodicity'), 3, 1) grid_layout.addWidget(self.periodicity_edit, 3, 2) grid_layout.addWidget(QLabel('Font'), 4, 1) grid_layout.addWidget(self.font_family_edit, 4, 2) grid_layout.addWidget(self.font_size_edit, 4, 3) grid_layout.addWidget(QLabel('Text color'), 5, 1) grid_layout.addWidget(self.color_edit, 5, 2) grid_layout.addWidget(QLabel('Notification sound'), 6, 1) grid_layout.addWidget(self.sound_edit, 6, 2) grid_layout.addWidget(self.accept_button, 7, 3) group_box.setLayout(grid_layout) group_box.adjustSize()
def test_sound_selector_widget_set_sound_wrong(): """Tests the :class:`~_clockalarm.UI.SoundSelectorWidget.set_sound` method. Incorrect sound argument. """ ss_widget = SoundSelectorWidget("mySound.wav") with pytest.raises(ValueError): ss_widget.set_sound("wrong_ext.mp3")
def test_sound_selector_widget_load_sound(): """Tests the :class:`~_clockalarm.UI.SoundSelectorWidget.load_sound` method.""" import pathlib ss_widget = SoundSelectorWidget("mySound.wav") src_sound_file = join(dirname(abspath(__file__)), "test_sound.wav") dest_sound_path = join(dirname(dirname(abspath(__file__))), "resources", "sounds") ss_widget.load_sound(pathlib.Path(src_sound_file).as_posix()) assert filecmp.cmp(src_sound_file, join(dest_sound_path, "test_sound.wav")) assert ss_widget.sound_name == "test_sound.wav" os.remove(join(dest_sound_path, "test_sound.wav"))
def test_sound_selector_widget_constructor(): """Tests the :class:`~_clockalarm.UI.SoundSelectorWidget` constructor.""" ss_widget = SoundSelectorWidget("mySound.wav") assert ss_widget.sound_name == "mySound.wav" assert isinstance(ss_widget.sound_edit, QLineEdit) assert ss_widget.sound_edit.text() == "mySound.wav" assert isinstance(ss_widget.sound_select_button, QPushButton)
def test_sound_selector_widget_constructor_wrong(): """Tests the :class:`~_clockalarm.UI.SoundSelectorWidget` constructor. Invalid sound_name argument. """ with pytest.raises(ValueError): SoundSelectorWidget("mySound.mp3")
def test_sound_selector_widget_load_sound_error(): """Tests the :class:`~_clockalarm.UI.SoundSelectorWidget.load_sound` method. Corrupted sound_path argument """ ss_widget = SoundSelectorWidget("mySound.wav") with pytest.raises(ValueError): ss_widget.load_sound(None) with pytest.raises(ValueError): ss_widget.load_sound("incorrect.mp3")