70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""Tests our Open Adw.ActionRow."""
|
|
import emmental.header.open
|
|
import pathlib
|
|
import unittest
|
|
from gi.repository import Gio
|
|
from gi.repository import Gtk
|
|
from gi.repository import Adw
|
|
|
|
|
|
class TestOpenRow(unittest.TestCase):
|
|
"""Test the Open row."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.row = emmental.header.open.OpenRow()
|
|
|
|
def test_action_row(self):
|
|
"""Check that the action row was set up properly."""
|
|
self.assertIsInstance(self.row, Adw.ActionRow)
|
|
self.assertIsInstance(self.row._prefix, Gtk.Image)
|
|
|
|
self.assertEqual(self.row.props.title, "Open File")
|
|
self.assertEqual(self.row.props.subtitle, "Select a file for playback")
|
|
self.assertTrue(self.row.props.activatable)
|
|
|
|
self.assertEqual(self.row._prefix.props.icon_name,
|
|
"document-open-symbolic")
|
|
|
|
def test_filter(self):
|
|
"""Check that the file filter is set up properly."""
|
|
self.assertIsInstance(self.row._filter, Gtk.FileFilter)
|
|
self.assertIsInstance(self.row._filters, Gio.ListStore)
|
|
|
|
self.assertEqual(self.row._filter.get_name(), "Audio Files")
|
|
self.assertEqual(self.row._filters[0], self.row._filter)
|
|
|
|
def test_dialog(self):
|
|
"""Check that the file dialog is set up properly."""
|
|
self.assertIsInstance(self.row._dialog, Gtk.FileDialog)
|
|
self.assertEqual(self.row._dialog.get_title(), "Pick a Track")
|
|
self.assertEqual(self.row._dialog.get_filters(),
|
|
self.row._filters)
|
|
self.assertTrue(self.row._dialog.get_modal())
|
|
|
|
def test_activate(self):
|
|
"""Test activating an OpenRow."""
|
|
listbox = Gtk.ListBox()
|
|
popover = Gtk.Popover(child=listbox)
|
|
listbox.append(self.row)
|
|
|
|
with unittest.mock.patch.object(popover, "popdown") as mock_popdown:
|
|
with unittest.mock.patch.object(self.row._dialog,
|
|
"open") as mock_open:
|
|
self.row.emit("activated")
|
|
mock_popdown.assert_called()
|
|
mock_open.assert_called_with(None, None,
|
|
self.row._OpenRow__async_ready)
|
|
|
|
with unittest.mock.patch.object(self.row._dialog,
|
|
"open_finish") as mock_finish:
|
|
task = Gio.Task()
|
|
signal = unittest.mock.Mock()
|
|
mock_finish.return_value = Gio.File.new_for_path("/a/b/c/1.ogg")
|
|
self.row.connect("track-requested", signal)
|
|
|
|
self.row._OpenRow__async_ready(self.row._dialog, task)
|
|
mock_finish.assert_called_with(task)
|
|
signal.assert_called_with(self.row, pathlib.Path("/a/b/c/1.ogg"))
|