emmental/rind/test_library.py

55 lines
1.8 KiB
Python

# Copyright 2019 (c) Anna Schumaker.
from . import gtk
from . import library
import curds
import os
import unittest
from gi.repository import Gtk
test_album = os.path.abspath("./trier/Test Library/Test Artist 02/Test Album 1")
class TestLibrary(unittest.TestCase):
def setUp(self):
curds.reset()
def tearDownClass():
curds.stop()
def test_init(self):
self.assertIsInstance(library.Add, Gtk.Button)
self.assertIsInstance(library.Cancel, Gtk.Button)
self.assertIsInstance(library.Chooser, Gtk.FileChooser)
self.assertIsInstance(library.Ok, Gtk.Button)
self.assertIsInstance(library.Popover, Gtk.Popover)
def test_add_cancel(self):
self.assertFalse(library.Popover.is_visible())
library.Add.clicked()
gtk.main_loop()
self.assertTrue(library.Popover.is_visible())
library.Cancel.clicked()
gtk.main_loop(iteration_delay=0.01)
self.assertFalse(library.Popover.is_visible())
self.assertEqual(curds.playlist.lookup("Libraries").n_children(), 0)
def test_add_ok(self):
music_dir = os.path.join(os.path.expanduser("~"), "Music")
self.assertFalse(library.Popover.is_visible())
library.Add.clicked()
gtk.main_loop()
self.assertTrue(library.Popover.is_visible())
self.assertEqual(library.Chooser.get_filename(), music_dir)
library.Chooser.set_filename(test_album)
gtk.main_loop(delay=0.1)
self.assertEqual(library.Chooser.get_filename(), test_album)
library.Ok.clicked()
gtk.main_loop(iteration_delay=0.01)
self.assertEqual(curds.playlist.lookup("Libraries").n_children(), 1)
self.assertFalse(library.Popover.is_visible())
curds.playlist.library.join()