Skip to content

Commit ed23e67

Browse files
committed
Test CI
1 parent d755bc5 commit ed23e67

3 files changed

Lines changed: 70 additions & 56 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
beefore --username github-actions --repository ${{ github.repository }} --pull-request ${{ github.event.number }} --commit ${{ github.event.pull_request.head.sha }} ${{ matrix.task }} .
2626
2727
smoke:
28-
name: Smoke test
28+
name: Smoke test (Linux)
2929
needs: beefore
3030
runs-on: ubuntu-latest
3131
steps:
@@ -41,10 +41,10 @@ jobs:
4141
pip install -e .
4242
- name: Test
4343
run: |
44-
python setup.py test
44+
xvfb-run -a -s '-screen 0 2048x1536x24' python setup.py test
4545
4646
python-versions:
47-
name: Python compatibility test
47+
name: Python compatibility test (Linux)
4848
needs: smoke
4949
runs-on: ubuntu-latest
5050
strategy:
@@ -53,7 +53,6 @@ jobs:
5353
python-version: [3.5, 3.6]
5454
steps:
5555
- uses: actions/checkout@v1
56-
- name: Copy Ahem font
5756
- name: Set up Python ${{ matrix.python-version }}
5857
uses: actions/setup-python@v1
5958
with:
@@ -65,10 +64,10 @@ jobs:
6564
pip install -e .
6665
- name: Test
6766
run: |
68-
python setup.py test
67+
xvfb-run -a -s '-screen 0 2048x1536x24' python setup.py test
6968
7069
windows:
71-
name: Winforms backend tests
70+
name: Windows tests
7271
needs: python-versions
7372
runs-on: windows-latest
7473
steps:
@@ -83,10 +82,11 @@ jobs:
8382
pip install -e .
8483
- name: Test
8584
run: |
85+
python tests/utils.py
8686
python setup.py test
8787
8888
macOS:
89-
name: macOS backend tests
89+
name: macOS tests
9090
needs: python-versions
9191
runs-on: macos-latest
9292
steps:
@@ -101,4 +101,5 @@ jobs:
101101
pip install -e .
102102
- name: Test
103103
run: |
104+
python tests/utils.py
104105
python setup.py test

colosseum/fonts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def check_font_family(value):
9393
elif sys.platform.startswith('linux'):
9494
return _check_font_family_linux(value)
9595
elif os.name == 'nt':
96-
return _check_font_family_mac(value)
96+
return _check_font_family_win(value)
9797
else:
9898
raise NotImplementedError('Cannot request fonts on this system!')
9999

tests/utils.py

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import shutil
44
import sys
5-
import time
65
from unittest import TestCase, expectedFailure
76

87
from colosseum.constants import BLOCK, HTML4, MEDIUM, THICK, THIN
@@ -133,31 +132,60 @@ def clean_layout(layout):
133132
def output_layout(layout, depth=1):
134133
if 'tag' in layout:
135134
return (' ' * depth
136-
+ '* {tag}{n[content][size][0]}x{n[content][size][1]}'
137-
' @ ({n[content][position][0]}, {n[content][position][1]})'
138-
'\n'.format(
139-
n=layout,
140-
tag=('<' + layout['tag'] + '> ') if 'tag' in layout else '',
141-
# text=(": '" + layout['text'] + "'") if 'text' in layout else ''
142-
)
143-
# + ' ' * depth
144-
# + ' padding: {n[padding_box][size][0]}x{n[padding_box][size][1]}'
145-
# ' @ ({n[padding_box][position][0]}, {n[padding_box][position][1]})'
146-
# '\n'.format(n=layout)
147-
# + ' ' * depth
148-
# + ' border: {n[border_box][size][0]}x{n[border_box][size][1]}'
149-
# ' @ ({n[border_box][position][0]}, {n[border_box][position][1]})'
150-
# '\n'.format(n=layout)
151-
+ ''.join(
152-
output_layout(child, depth=depth + 1)
153-
for child in layout.get('children', [])
154-
) if layout else ''
155-
+ ('\n' if layout and layout.get('children', None) and depth > 1 else '')
156-
)
135+
+ '* {tag}{n[content][size][0]}x{n[content][size][1]}'
136+
' @ ({n[content][position][0]}, {n[content][position][1]})'
137+
'\n'.format(
138+
n=layout,
139+
tag=('<' + layout['tag'] + '> ') if 'tag' in layout else '',
140+
# text=(": '" + layout['text'] + "'") if 'text' in layout else ''
141+
)
142+
# + ' ' * depth
143+
# + ' padding: {n[padding_box][size][0]}x{n[padding_box][size][1]}'
144+
# ' @ ({n[padding_box][position][0]}, {n[padding_box][position][1]})'
145+
# '\n'.format(n=layout)
146+
# + ' ' * depth
147+
# + ' border: {n[border_box][size][0]}x{n[border_box][size][1]}'
148+
# ' @ ({n[border_box][position][0]}, {n[border_box][position][1]})'
149+
# '\n'.format(n=layout)
150+
+ ''.join(
151+
output_layout(child, depth=depth + 1)
152+
for child in layout.get('children', [])
153+
) if layout else ''
154+
+ ('\n' if layout and layout.get('children', None) and depth > 1 else ''))
157155
else:
158-
return (' ' * depth
159-
+ "* '{text}'\n".format(text=layout['text'].strip())
160-
)
156+
return (' ' * depth + "* '{text}'\n".format(text=layout['text'].strip()))
157+
158+
159+
def fonts_path(system=False):
160+
"""Return the path for cross platform user fonts."""
161+
if os.name == 'nt':
162+
import winreg
163+
fonts_dir = os.path.join(winreg.ExpandEnvironmentStrings('%windir%'), 'fonts')
164+
elif sys.platform == 'darwin':
165+
if system:
166+
fonts_dir = os.path.expanduser('/Library/Fonts')
167+
else:
168+
fonts_dir = os.path.expanduser('~/Library/Fonts')
169+
elif sys.platform.startswith('linux'):
170+
fonts_dir = os.path.expanduser('~/.local/share/fonts/')
171+
else:
172+
raise NotImplementedError('System not supported!')
173+
174+
return fonts_dir
175+
176+
177+
def copy_fonts(system=False):
178+
"""Copy needed files for running tests."""
179+
fonts_folder = fonts_path(system=system)
180+
if not os.path.isdir(fonts_folder):
181+
os.makedirs(fonts_folder)
182+
fonts_data_path = os.path.join(HERE, 'data', 'fonts')
183+
font_files = sorted([item for item in os.listdir(fonts_data_path) if item.endswith('.ttf')])
184+
for font_file in font_files:
185+
font_file_data_path = os.path.join(fonts_data_path, font_file)
186+
font_file_path = os.path.join(fonts_folder, font_file)
187+
if not os.path.isfile(font_file_path):
188+
shutil.copyfile(font_file_data_path, font_file_path)
161189

162190

163191
class ColosseumTestCase(TestCase):
@@ -167,30 +195,8 @@ def __init__(self, *args, **kwargs):
167195
super().__init__(*args, **kwargs)
168196
self.copy_fonts()
169197

170-
def fonts_path(self):
171-
"""Return the path for cross platform user fonts."""
172-
if os.name == 'nt':
173-
import winreg
174-
fonts_dir = os.path.join(winreg.ExpandEnvironmentStrings('%windir%'), 'fonts')
175-
elif sys.platform == 'darwin':
176-
fonts_dir = os.path.expanduser('~/Library/Fonts')
177-
elif sys.platform.startswith('linux'):
178-
fonts_dir = os.path.expanduser('~/.local/share/fonts/')
179-
else:
180-
raise NotImplementedError('System not supported!')
181-
182-
return fonts_dir
183-
184198
def copy_fonts(self):
185-
"""Copy needed files for running tests."""
186-
fonts_path = self.fonts_path()
187-
fonts_data_path = os.path.join(HERE, 'data', 'fonts')
188-
font_files = sorted([item for item in os.listdir(fonts_data_path) if item.endswith('.ttf')])
189-
for font_file in font_files:
190-
font_file_data_path = os.path.join(fonts_data_path, font_file)
191-
font_file_path = os.path.join(fonts_path, font_file)
192-
if not os.path.isfile(font_file_path):
193-
shutil.copyfile(font_file_data_path, font_file_path)
199+
copy_fonts()
194200

195201
try:
196202
FontDatabase.validate_font_family('Ahem')
@@ -442,3 +448,10 @@ def test_method(self):
442448
tests[test_name] = test_method
443449

444450
return tests
451+
452+
453+
if __name__ == '__main__':
454+
print('Copying test fonts...')
455+
print(fonts_path(system=True))
456+
copy_fonts(system=True)
457+
print(list(sorted(os.listdir(fonts_path()))))

0 commit comments

Comments
 (0)