diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b83be6016..0e32531fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,9 +11,6 @@ jobs: task: ['pycodestyle'] steps: - uses: actions/checkout@v1 - - name: Copy Ahem font - run: | - cp tests/fonts/ahem.ttf ~/.fonts/ahem.ttf - name: Set up Python 3.7 uses: actions/setup-python@v1 with: @@ -33,6 +30,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 + - name: Copy Ahem font + run: | + mkdir -p ~/.local/share/fonts/ + cp tests/fonts/ahem.ttf ~/.local/share/fonts/ahem.ttf - name: Set up Python 3.7 uses: actions/setup-python@v1 with: @@ -55,6 +56,10 @@ jobs: python-version: [3.5, 3.6] steps: - uses: actions/checkout@v1 + - name: Copy Ahem font + run: | + mkdir -p ~/.local/share/fonts/ + cp tests/fonts/ahem.ttf ~/.local/share/fonts/ahem.ttf - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: diff --git a/colosseum/constants.py b/colosseum/constants.py index 90a5c9d4f..396632624 100644 --- a/colosseum/constants.py +++ b/colosseum/constants.py @@ -1,4 +1,3 @@ -import os import sys from .validators import (ValidationError, is_color, is_font_family, @@ -334,10 +333,6 @@ def __str__(self): def available_font_families(): """List available font family names.""" - # TODO: for tests - if os.environ.get('GITHUB_ACTIONS', None) == 'true': - return ['Arial Black'] - if sys.platform == 'darwin': return _available_font_families_mac() elif sys.platform.startswith('linux'): @@ -356,7 +351,7 @@ def _available_font_families_mac(): NSFontManager.declare_class_property("sharedFontManager") NSFontManager.declare_property("availableFontFamilies") manager = NSFontManager.sharedFontManager - return list(sorted(str(item) for item in manager.availableFontFamilies)) + return list(sorted(str(item) for item in manager.availableFontFamilies if item)) def _available_font_families_unix(): @@ -364,7 +359,7 @@ def _available_font_families_unix(): import subprocess p = subprocess.check_output(['fc-list', ':', 'family']) fonts = p.decode().split('\n') - return list(sorted(set(fonts))) + return list(sorted(set(item for item in fonts if item))) AVAILABLE_FONT_FAMILIES = available_font_families() diff --git a/tests/test_declaration.py b/tests/test_declaration.py index 8d12778cc..dd80244e7 100644 --- a/tests/test_declaration.py +++ b/tests/test_declaration.py @@ -443,17 +443,17 @@ def test_list_property(self): # Check valid values node.style.font_family = ['serif'] - node.style.font_family = ["'Arial Black'", 'serif'] + node.style.font_family = ["'DejaVu Sans'", 'serif'] # TODO: This will coerce to a list, is this a valid behavior? - node.style.font_family = '"Arial Black"' - self.assertEqual(node.style.font_family, ['"Arial Black"']) - node.style.font_family = ' " Arial Black " , serif ' - self.assertEqual(node.style.font_family, ['"Arial Black"', 'serif']) + node.style.font_family = '"DejaVu Sans"' + self.assertEqual(node.style.font_family, ['"DejaVu Sans"']) + node.style.font_family = ' " DejaVu Sans " , serif ' + self.assertEqual(node.style.font_family, ['"DejaVu Sans"', 'serif']) # Check invalid values with self.assertRaises(ValueError): - node.style.font_family = ['Arial Black'] + node.style.font_family = ['DejaVu Sans'] # Check the error message try: @@ -711,9 +711,9 @@ def test_font_shorthand_property(self): node.style.font_variant = 'small-caps' node.style.font_size = '10px' node.style.line_height = '1.5' - node.style.font_family = ['"Arial Black"', 'serif'] + node.style.font_family = ['"DejaVu Sans"', 'serif'] # TODO: Is this the behavior we want? - self.assertEqual(node.style.font, 'italic small-caps bold 10.0px/1.5 "Arial Black", serif') + self.assertEqual(node.style.font, 'italic small-caps bold 10.0px/1.5 "DejaVu Sans", serif') # Check setting the shorthand resets values node.style.font = '9px serif' @@ -733,7 +733,7 @@ def test_font_shorthand_property(self): node.style.font_variant = 'small-caps' node.style.font_size = '10px' node.style.line_height = '1.5' - node.style.font_family = ['"Arial Black"', 'serif'] + node.style.font_family = ['"DejaVu Sans"', 'serif'] self.assertEqual(node.style.font, '9px serif') # Check invalid values diff --git a/tests/test_fonts.py b/tests/test_fonts.py index cd844359d..544300883 100644 --- a/tests/test_fonts.py +++ b/tests/test_fonts.py @@ -22,13 +22,13 @@ 'line_height': 'normal', 'font_family': ['sans-serif'], }, - r'bold italic large Palatino, serif': { + r'bold italic large Ahem, serif': { 'font_style': 'italic', 'font_variant': 'normal', 'font_weight': 'bold', 'font_size': 'large', 'line_height': 'normal', - 'font_family': ['Palatino', 'serif'], + 'font_family': ['Ahem', 'serif'], }, r'normal small-caps 120%/120% fantasy': { 'font_style': 'normal', @@ -38,13 +38,13 @@ 'line_height': '120%', 'font_family': ['fantasy'], }, - r'x-large/110% "Arial Black",serif': { + r'x-large/110% "DejaVu Sans",serif': { 'font_style': 'normal', 'font_variant': 'normal', 'font_weight': 'normal', 'font_size': 'x-large', 'line_height': '110%', - 'font_family': ['"Arial Black"', 'serif'], + 'font_family': ['"DejaVu Sans"', 'serif'], }, } @@ -58,7 +58,7 @@ def test_parse_font_shorthand(self): # Test extra spaces parse_font_property(r' normal normal normal 12px/12px serif ') - parse_font_property(r' normal normal normal 12px/12px " Arial Black ", serif ') + parse_font_property(r' normal normal normal 12px/12px " DejaVu Sans ", serif ') # Test valid single part for part in SYSTEM_FONT_KEYWORDS: diff --git a/tests/test_validators.py b/tests/test_validators.py index 19237a5b7..1edaf654f 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -44,10 +44,10 @@ def test_number(self): class FontTests(TestCase): def test_font_family_name_valid(self): - validator = is_font_family(generic_family=GENERIC_FAMILY_FONTS, font_families=['Arial Black']) - self.assertEqual(validator('"Arial Black", serif'), ['"Arial Black"', 'serif']) - self.assertEqual(validator("'Arial Black',fantasy"), ["'Arial Black'", 'fantasy']) - self.assertEqual(validator(" ' Arial Black ' , fantasy "), ["'Arial Black'", 'fantasy']) + validator = is_font_family(generic_family=GENERIC_FAMILY_FONTS, font_families=['DejaVu Sans']) + self.assertEqual(validator('"DejaVu Sans", serif'), ['"DejaVu Sans"', 'serif']) + self.assertEqual(validator("'DejaVu Sans',fantasy"), ["'DejaVu Sans'", 'fantasy']) + self.assertEqual(validator(" ' DejaVu Sans ' , fantasy "), ["'DejaVu Sans'", 'fantasy']) def test_font_family_name_invalid(self): validator = is_font_family(generic_family=GENERIC_FAMILY_FONTS)