sidebar: Create a BaseRow widget

This is intended to be used as a base class for our playlist Row
widgets, and sets up some common variables needed by both.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2022-08-15 15:45:53 -04:00
parent b25ca24dc3
commit bf4fa68991
2 changed files with 53 additions and 0 deletions

13
emmental/sidebar/row.py Normal file
View File

@ -0,0 +1,13 @@
# Copyright 2022 (c) Anna Schumaker.
"""Widgets for sidebar rows."""
from gi.repository import GObject
from gi.repository import Gtk
from .. import db
class BaseRow(Gtk.Box):
"""Base class for Row widgets."""
playlist = GObject.Property(type=db.playlist.Playlist)
name = GObject.Property(type=str)
count = GObject.Property(type=int)

40
tests/sidebar/test_row.py Normal file
View File

@ -0,0 +1,40 @@
# Copyright 2022 (c) Anna Schumaker.
"""Tests our sidebar row widgets."""
import unittest
import emmental.sidebar.row
from gi.repository import Gio
from gi.repository import Gtk
class TestBaseRow(unittest.TestCase):
"""Test our BaseRow class."""
def setUp(self):
"""Set up common variables."""
self.row = emmental.sidebar.row.BaseRow()
def test_init(self):
"""Test that the BaseRow is configured correctly."""
self.assertIsInstance(self.row, Gtk.Box)
self.assertEqual(self.row.get_orientation(),
Gtk.Orientation.HORIZONTAL)
def test_name(self):
"""Test the name property."""
self.assertEqual(self.row.name, "")
row2 = emmental.sidebar.row.BaseRow(name="Test Playlist")
self.assertEqual(row2.name, "Test Playlist")
def test_count(self):
"""Test the count property."""
self.assertEqual(self.row.count, 0)
row2 = emmental.sidebar.row.BaseRow(count=42)
self.assertEqual(row2.count, 42)
def test_playlist(self):
"""Test the playlist property."""
plist = emmental.db.playlist.Playlist(Gio.ListStore(),
0, "Playlist Name")
self.assertIsNone(self.row.playlist)
row2 = emmental.sidebar.row.BaseRow(playlist=plist)
self.assertEqual(row2.playlist, plist)