52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""Tests our custom button classes."""
|
|
import unittest
|
|
import xfstestsdb.gtk.button
|
|
from gi.repository import Gtk
|
|
|
|
|
|
class TestStatusToggle(unittest.TestCase):
|
|
"""Test our StatusToggle button."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.button = xfstestsdb.gtk.button.StatusToggle("icon-name",
|
|
"css-class")
|
|
|
|
def test_button(self):
|
|
"""Test the StatusToggle button."""
|
|
self.assertIsInstance(self.button, Gtk.Button)
|
|
self.assertEqual(self.button.icon_name, "icon-name")
|
|
self.assertTrue(self.button.has_css_class("css-class"))
|
|
|
|
self.assertFalse(self.button.props.has_frame)
|
|
self.assertFalse(self.button.active)
|
|
|
|
button2 = xfstestsdb.gtk.button.StatusToggle("icon-name", "css-class",
|
|
active=True)
|
|
self.assertTrue(button2.active)
|
|
self.assertAlmostEqual(button2.props.child.props.opacity, 1.0)
|
|
|
|
def test_image(self):
|
|
"""Test that the image is set up correctly, and opacity changes."""
|
|
self.assertIsInstance(self.button.props.child, Gtk.Image)
|
|
self.assertEqual(self.button.props.child.props.icon_name, "icon-name")
|
|
|
|
self.button.active = True
|
|
self.assertAlmostEqual(self.button.props.child.props.opacity, 1.0)
|
|
self.button.active = False
|
|
self.assertAlmostEqual(self.button.props.child.props.opacity, 0.4)
|
|
|
|
def test_clicked(self):
|
|
"""Test clicking the CSSToggle button."""
|
|
self.assertFalse(self.button.active)
|
|
self.assertAlmostEqual(self.button.props.child.props.opacity, 0.4)
|
|
|
|
self.button.emit("clicked")
|
|
self.assertTrue(self.button.active)
|
|
self.assertAlmostEqual(self.button.props.child.props.opacity, 1.0)
|
|
|
|
self.button.emit("clicked")
|
|
self.assertFalse(self.button.active)
|
|
self.assertAlmostEqual(self.button.props.child.props.opacity, 0.4)
|