Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start pytest migration to modern pytest with conftest and fixtures
- Loading branch information
Julian Psotta
committed
Feb 6, 2021
1 parent
9504c36
commit 07265e5
Showing
3 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
import codecs | ||
import openrouteservice | ||
|
||
from urllib.parse import urlparse, parse_qsl | ||
|
||
# For relative imports to work in Python 3.6 | ||
import os | ||
import sys | ||
import pytest | ||
|
||
sys.path.append(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
|
||
class TestCase(unittest.TestCase): | ||
def setUp(self): | ||
self.key = "sample_key" | ||
self.client = openrouteservice.Client(self.key) | ||
|
||
def assertURLEqual(self, first, second, msg=None): | ||
"""Check that two arguments are equivalent URLs. Ignores the order of | ||
query arguments. | ||
""" | ||
first_parsed = urlparse(first) | ||
second_parsed = urlparse(second) | ||
self.assertEqual(first_parsed[:3], second_parsed[:3], msg) | ||
|
||
first_qsl = sorted(parse_qsl(first_parsed.query)) | ||
second_qsl = sorted(parse_qsl(second_parsed.query)) | ||
self.assertEqual(first_qsl, second_qsl, msg) | ||
|
||
@staticmethod | ||
def u(string): | ||
"""Create a unicode string, compatible across all versions of Python.""" | ||
# NOTE(cbro): Python 3-3.2 does not have the u'' syntax. | ||
return codecs.unicode_escape_decode(string)[0] | ||
|
||
def assertDictContainsSubset(self, a, b, **kwargs): | ||
"""Replaces deprecated unittest.TestCase.assertDictContainsSubset""" | ||
c = dict([(k, b[k]) for k in a.keys() if k in b.keys()]) | ||
self.assertEqual(a, c) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def simpletestcase(): | ||
test_case = TestCase() | ||
test_case.setUp() | ||
yield test_case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters