From f56696378095df8a1f29ba2bccbe12fcc4bde644 Mon Sep 17 00:00:00 2001 From: Kamil Date: Fri, 1 May 2020 00:37:21 +0200 Subject: [PATCH 1/2] Corrected two xml style code comparison --- noxfile.py | 2 +- setup.py | 2 +- tests/test_pybadges.py | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 61c6191..d111040 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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.""" diff --git a/setup.py b/setup.py index 83b0671..0ea31d3 100644 --- a/setup.py +++ b/setup.py @@ -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"], diff --git a/tests/test_pybadges.py b/tests/test_pybadges.py index 9710511..b85c1e5 100644 --- a/tests/test_pybadges.py +++ b/tests/test_pybadges.py @@ -21,6 +21,7 @@ import unittest import pathlib import tempfile +import xmldiff.main import pybadges @@ -53,11 +54,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.""" From e728828a3e475789a4bb85dab21380fcf5a2bbcf Mon Sep 17 00:00:00 2001 From: Kamil Date: Fri, 1 May 2020 01:17:50 +0200 Subject: [PATCH 2/2] Skipped windows incompatible tests --- tests/test_pybadges.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_pybadges.py b/tests/test_pybadges.py index b85c1e5..3da2438 100644 --- a/tests/test_pybadges.py +++ b/tests/test_pybadges.py @@ -20,6 +20,7 @@ import os.path import unittest import pathlib +import sys import tempfile import xmldiff.main @@ -78,12 +79,14 @@ 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) @@ -91,6 +94,7 @@ def test_png_file_path(self): 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') @@ -99,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')