Skip to content

Commit

Permalink
Copy ahem font
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Jan 4, 2020
1 parent 925bf17 commit bc376e5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,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:
Expand All @@ -52,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:
Expand Down
9 changes: 2 additions & 7 deletions colosseum/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import sys

from .validators import (ValidationError, is_color, is_font_family,
Expand Down Expand Up @@ -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'):
Expand All @@ -356,15 +351,15 @@ 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():
"""List available font family names on 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()
Expand Down
Binary file added tests/fonts/ahem.ttf
Binary file not shown.
18 changes: 9 additions & 9 deletions tests/test_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/test_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'],
},
}

Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bc376e5

Please sign in to comment.