File: test_customizableplot.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (38 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download | duplicates (2)
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
import unittest
from unittest.mock import patch, Mock

from Orange.widgets.visualize.utils import customizableplot


class TestFonts(unittest.TestCase):
    def test_available_font_families(self):
        with patch.object(customizableplot, "QFont") as font, \
                patch.object(customizableplot, "QFontDatabase") as db:
            font.return_value = Mock()
            font.return_value.family = Mock(return_value="mock regular")

            db.return_value = Mock()
            db.families = Mock(
                return_value=["a", ".d", "e", ".b", "mock regular", "c"])
            self.assertEqual(customizableplot.available_font_families(),
                             ["mock regular", "", "a", ".b", "c", ".d", "e"])

            db.return_value = Mock()
            db.families = Mock(
                return_value=["a", ".d", "e", ".b", "mock regular",
                              "mock bold", "mock italic", "c", "mock semi"])
            self.assertEqual(customizableplot.available_font_families(),
                             ["mock regular", "mock bold", "mock italic",
                              "mock semi", "",
                              "a", ".b", "c", ".d", "e"])

            # It seems it's possible that default font family does not exist
            # (see gh-5036)
            db.return_value.families.return_value = ["a", ".d", "e", ".b", "c"]
            self.assertEqual(customizableplot.available_font_families(),
                             ["mock regular", "", "a", ".b", "c", ".d", "e"])
            self.assertIn(customizableplot.default_font_family(),
                          customizableplot.available_font_families())

if __name__ == "__main__":
    unittest.main()