Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def unit(session):

@nox.session(python=['3.4', '3.5', '3.6', '3.7'])
@nox.parametrize('install',
['Jinja2==2.9.0', 'Pillow==5.0.0', 'requests==2.9.0'])
['Jinja2==2.9.0', 'Pillow==5.0.0', 'requests==2.9.0', 'xmldiff==2.4'])
def compatibility(session, install):
"""Run the unit test suite with each support library and Python version."""

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def replace_relative_with_absolute(match):
extras_require={
'pil-measurement': ['Pillow>=5,<6'],
'dev': ['fonttools>=3.26', 'nox', 'Pillow>=5',
'pytest>=3.6'],
'pytest>=3.6', 'xmldiff>=2.4'],
},
license='Apache-2.0',
packages=["pybadges"],
Expand Down
11 changes: 9 additions & 2 deletions tests/test_pybadges.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import os.path
import unittest
import pathlib
import sys
import tempfile
import xmldiff.main

import pybadges

Expand Down Expand Up @@ -53,11 +55,12 @@ def test_changes(self):
with self.subTest(example=file_name):
filepath = os.path.join(TEST_DIR, 'golden-images', file_name)

with open(filepath, 'r') as f:
with open(filepath, mode="r", encoding="utf-8") as f:
golden_image = f.read()
pybadge_image = pybadges.badge(**example)
self.assertEqual(golden_image, pybadge_image)

diff = xmldiff.main.diff_texts(golden_image, pybadge_image)
self.assertFalse(diff)

class TestEmbedImage(unittest.TestCase):
"""Tests for pybadges._embed_image."""
Expand All @@ -76,19 +79,22 @@ def test_not_image_url(self):
'expected an image, got "text"'):
pybadges._embed_image('http://www.google.com/')

@unittest.skipIf(sys.platform.startswith("win"), "requires Unix filesystem")
def test_svg_file_path(self):
image_path = os.path.abspath(
os.path.join(TEST_DIR, 'golden-images', 'build-failure.svg'))
self.assertRegex(pybadges._embed_image(image_path),
r'^data:image/svg(\+xml)?;base64,')

@unittest.skipIf(sys.platform.startswith("win"), "requires Unix filesystem")
def test_png_file_path(self):
with tempfile.NamedTemporaryFile() as png:
png.write(PNG_IMAGE)
png.flush()
self.assertEqual(pybadges._embed_image(png.name),
'data:image/png;base64,' + PNG_IMAGE_B64)

@unittest.skipIf(sys.platform.startswith("win"), "requires Unix filesystem")
def test_unknown_type_file_path(self):
with tempfile.NamedTemporaryFile() as non_image:
non_image.write(b'Hello')
Expand All @@ -97,6 +103,7 @@ def test_unknown_type_file_path(self):
'not able to determine file type'):
pybadges._embed_image(non_image.name)

@unittest.skipIf(sys.platform.startswith("win"), "requires Unix filesystem")
def test_text_file_path(self):
with tempfile.NamedTemporaryFile(suffix='.txt') as non_image:
non_image.write(b'Hello')
Expand Down