1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
# -*- coding: utf-8 -*-
"""
Tests for the resources sub-module.
"""
import mu.resources
from unittest import mock
from PyQt5.QtGui import QIcon, QPixmap
def test_path():
"""
Ensure the resource_filename function is called with the expected args and
the path function under test returns its result.
"""
with mock.patch('mu.resources.resource_filename', return_value='bar') as r:
assert mu.resources.path('foo') == 'bar'
r.assert_called_once_with(mu.resources.__name__, 'images/foo')
def test_load_icon():
"""
Check the load_icon function returns the expected QIcon object.
"""
result = mu.resources.load_icon('icon')
assert isinstance(result, QIcon)
def test_load_pixmap():
"""
Check the load_pixmap function returns the expected QPixmap object.
"""
result = mu.resources.load_pixmap('icon')
assert isinstance(result, QPixmap)
def test_stylesheet():
"""
Ensure the resource_string function is called with the expected args and
the load_stylesheet function returns its result.
"""
with mock.patch('mu.resources.resource_string', return_value=b'foo') as rs:
assert 'foo' == mu.resources.load_stylesheet('foo')
rs.assert_called_once_with(mu.resources.__name__, 'css/foo')
def test_load_font_data():
"""
Ensure font data can be loaded
"""
with mock.patch('mu.resources.resource_string', return_value=b'foo') as rs:
assert b'foo' == mu.resources.load_font_data('foo')
rs.assert_called_once_with(mu.resources.__name__, 'fonts/foo')
|