-
-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5037 from janezd/non-existent-default-font-family
customizableplot.available_font_families: Fix for non-existent default family
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Orange/widgets/visualize/utils/tests/test_customizableplot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.return_value.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.return_value.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() |