From d4ce8c74cef9dd8ef246b3ce5689fc488c511834 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 6 Sep 2018 16:49:51 +0300 Subject: Fix pep8 --- tests/test_uritemplate.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/test_uritemplate.py b/tests/test_uritemplate.py index b1abc96..7448be0 100644 --- a/tests/test_uritemplate.py +++ b/tests/test_uritemplate.py @@ -544,24 +544,24 @@ class TestURIVariable(TestCase): class TestVariableModule(TestCase): def test_is_list_of_tuples(self): - l = [(1, 2), (3, 4)] - self.assertEqual(variable.is_list_of_tuples(l), (True, l)) + a_list = [(1, 2), (3, 4)] + self.assertEqual(variable.is_list_of_tuples(a_list), (True, a_list)) - l = [1, 2, 3, 4] - self.assertEqual(variable.is_list_of_tuples(l), (False, None)) + a_list = [1, 2, 3, 4] + self.assertEqual(variable.is_list_of_tuples(a_list), (False, None)) def test_list_test(self): - l = [1, 2, 3, 4] - self.assertEqual(variable.list_test(l), True) + a_list = [1, 2, 3, 4] + self.assertEqual(variable.list_test(a_list), True) - l = str([1, 2, 3, 4]) - self.assertEqual(variable.list_test(l), False) + a_list = str([1, 2, 3, 4]) + self.assertEqual(variable.list_test(a_list), False) def test_list_of_tuples_test(self): - l = [(1, 2), (3, 4)] - self.assertEqual(variable.dict_test(l), False) + a_list = [(1, 2), (3, 4)] + self.assertEqual(variable.dict_test(a_list), False) - d = dict(l) + d = dict(a_list) self.assertEqual(variable.dict_test(d), True) -- cgit v1.2.3 From 910f60597444da9b9ffc680f73050f6d67083403 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 6 Sep 2018 16:59:32 +0300 Subject: Upgrade Python syntax with pyupgrade https://github.com/asottile/pyupgrade --- tests/test_from_fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_from_fixtures.py b/tests/test_from_fixtures.py index 70d6553..c21d395 100644 --- a/tests/test_from_fixtures.py +++ b/tests/test_from_fixtures.py @@ -20,7 +20,7 @@ def load_examples(filename): def expected_set(expected): if isinstance(expected, list): return set(expected) - return set([expected]) + return {expected} class FixtureMixin(object): -- cgit v1.2.3 From 21afcf2c35f21034124a230abebd1157cbee8265 Mon Sep 17 00:00:00 2001 From: Tommy Yu Date: Thu, 11 Jul 2019 22:21:14 +1200 Subject: Tests covering current correct behaviors. --- tests/test_uritemplate.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/test_uritemplate.py b/tests/test_uritemplate.py index 7448be0..9977ef7 100644 --- a/tests/test_uritemplate.py +++ b/tests/test_uritemplate.py @@ -464,6 +464,40 @@ class TestURITemplate(RFCTemplateExamples('RFCMeta', (TestCase,), {})): None ) + def test_label_path_expansion_explode_slash(self): + t = URITemplate('{/foo*}') + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one'], True, '/'), 'one' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one', 'two'], True, '/'), 'one/two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['', ''], True, '/'), '/' + ) + + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {}, True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': ''}, True, '/'), 'one=' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': '', 'two': ''}, True, '/'), 'one=/two=' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None}, True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None, 'two': 'two'}, True, '/'), 'two=two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None, 'two': None}, True, '/'), None + ) + def test_semi_path_expansion(self): t = URITemplate('{foo}') v = t.variables[0] -- cgit v1.2.3 From abb1308fa8b7c50eb79e9f07ee448a76c7449847 Mon Sep 17 00:00:00 2001 From: Tommy Yu Date: Thu, 11 Jul 2019 22:27:22 +1200 Subject: Correct handling of empty/undef in list values - Expansion of a list including `None` values, violating 3.2.1 as the undefined value is not ignored, e.g. >>> expand('/test{/x*}', x=['one', None, 'three']) '/test/one/None/three' - A list with empty string was ignored, violating 2.3 as this should not be tread as undefined, example: >>> expand('/test{/x}', x=[]) '/test' >>> expand('/test{/x}', x='') '/test/' >>> expand('/test{/x}', x=['']) '/test' # should be /test/ >>> expand('/test{/x}', x=['', '']) '/test/,' >>> expand('/test{/x*}', x=['', '']) '/test//' >>> expand('/test{/x*}', x=['']) '/test' --- tests/test_uritemplate.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/test_uritemplate.py b/tests/test_uritemplate.py index 9977ef7..f67ad26 100644 --- a/tests/test_uritemplate.py +++ b/tests/test_uritemplate.py @@ -469,12 +469,24 @@ class TestURITemplate(RFCTemplateExamples('RFCMeta', (TestCase,), {})): self.assertEqual(t.variables[0]._label_path_expansion( 'foo', [], True, '/'), None ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [None], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [None, None], True, '/'), None + ) self.assertEqual(t.variables[0]._label_path_expansion( 'foo', ['one'], True, '/'), 'one' ) self.assertEqual(t.variables[0]._label_path_expansion( 'foo', ['one', 'two'], True, '/'), 'one/two' ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one', None, 'two'], True, '/'), 'one/two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [''], True, '/'), '' + ) self.assertEqual(t.variables[0]._label_path_expansion( 'foo', ['', ''], True, '/'), '/' ) -- cgit v1.2.3 From ab215b3eb7b16801d5a13267570caaa944cab3d6 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 2 Dec 2019 11:18:45 -0800 Subject: Update support for Python 3.7 & 3.8 Starting in Python 3.7 the quoting support changed from RFC 2396 to RFC 3986. --- tests/fixtures/extended-tests.json | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/fixtures/extended-tests.json b/tests/fixtures/extended-tests.json index fd69744..3fd88f9 100644 --- a/tests/fixtures/extended-tests.json +++ b/tests/fixtures/extended-tests.json @@ -11,7 +11,7 @@ "lang" : "en", "geocode" : ["37.76","-122.427"], "first_name" : "John", - "last.name" : "Doe", + "last.name" : "Doe", "Some%20Thing" : "foo", "number" : 6, "long" : 37.76, @@ -28,7 +28,7 @@ "testcases":[ [ "{/id*}" , "/person" ], - [ "{/id*}{?fields,first_name,last.name,token}" , [ + [ "{/id*}{?fields,first_name,last.name,token}" , [ "/person?fields=id,name,picture&first_name=John&last.name=Doe&token=12345", "/person?fields=id,picture,name&first_name=John&last.name=Doe&token=12345", "/person?fields=picture,name,id&first_name=John&last.name=Doe&token=12345", @@ -46,10 +46,16 @@ ["/base{/group_id,first_name}/pages{/page,lang}{?format,q}","/base/12345/John/pages/5/en?format=json&q=URI%20Templates"], ["/sparql{?query}", "/sparql?query=PREFIX%20dc%3A%20%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%20SELECT%20%3Fbook%20%3Fwho%20WHERE%20%7B%20%3Fbook%20dc%3Acreator%20%3Fwho%20%7D"], ["/go{?uri}", "/go?uri=http%3A%2F%2Fexample.org%2F%3Furi%3Dhttp%253A%252F%252Fexample.org%252F"], - ["/service{?word}", "/service?word=dr%C3%BCcken"], - ["/lookup{?Stra%C3%9Fe}", "/lookup?Stra%C3%9Fe=Gr%C3%BCner%20Weg"], - ["{random}" , "%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF"], - ["{?assoc_special_chars*}", "?%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95=%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF"] + ["/service{?word}", [ "/service?word=dr%C3%BCcken", "/service?word=dr%C3%83%C2%BCcken"]], + ["/lookup{?Stra%C3%9Fe}", ["/lookup?Stra%C3%9Fe=Gr%C3%BCner%20Weg", "/lookup?Stra%C3%9Fe=Gr%C3%83%C2%BCner%20Weg"]], + ["{random}", + [ "%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF", + "%C3%85%C2%A1%C3%83%C2%B6%C3%83%C2%A4%C3%85%C2%B8%C3%85%E2%80%9C%C3%83%C2%B1%C3%83%C2%AA%C3%A2%E2%80%9A%C2%AC%C3%82%C2%A3%C3%82%C2%A5%C3%A2%E2%82%AC%C2%A1%C3%83%E2%80%98%C3%83%E2%80%99%C3%83%E2%80%9C%C3%83%E2%80%9D%C3%83%E2%80%A2%C3%83%E2%80%93%C3%83%E2%80%94%C3%83%CB%9C%C3%83%E2%84%A2%C3%83%C5%A1%C3%83%C2%A0%C3%83%C2%A1%C3%83%C2%A2%C3%83%C2%A3%C3%83%C2%A4%C3%83%C2%A5%C3%83%C2%A6%C3%83%C2%A7%C3%83%C2%BF"] + ], + ["{?assoc_special_chars*}", + [ "?%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95=%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF", + "?%C3%85%C2%A1%C3%83%C2%B6%C3%83%C2%A4%C3%85%C2%B8%C3%85%E2%80%9C%C3%83%C2%B1%C3%83%C2%AA%C3%A2%E2%80%9A%C2%AC%C3%82%C2%A3%C3%82%C2%A5%C3%A2%E2%82%AC%C2%A1%C3%83%E2%80%98%C3%83%E2%80%99%C3%83%E2%80%9C%C3%83%E2%80%9D%C3%83%E2%80%A2=%C3%83%E2%80%93%C3%83%E2%80%94%C3%83%CB%9C%C3%83%E2%84%A2%C3%83%C5%A1%C3%83%C2%A0%C3%83%C2%A1%C3%83%C2%A2%C3%83%C2%A3%C3%83%C2%A4%C3%83%C2%A5%C3%83%C2%A6%C3%83%C2%A7%C3%83%C2%BF"] + ] ] }, "Additional Examples 2":{ @@ -68,7 +74,7 @@ "testcases":[ [ "{/id*}" , ["/person/albums","/albums/person"] ], - [ "{/id*}{?fields,token}" , [ + [ "{/id*}{?fields,token}" , [ "/person/albums?fields=id,name,picture&token=12345", "/person/albums?fields=id,picture,name&token=12345", "/person/albums?fields=picture,name,id&token=12345", @@ -112,7 +118,7 @@ [ "{?42}", "?42=The%20Answer%20to%20the%20Ultimate%20Question%20of%20Life%2C%20the%20Universe%2C%20and%20Everything"], [ "{1337}", "leet,as,it,can,be"], [ "{?1337*}", "?1337=leet&1337=as&1337=it&1337=can&1337=be"], - [ "{?german*}", [ "?11=elf&12=zw%C3%B6lf", "?12=zw%C3%B6lf&11=elf"] ] + [ "{?german*}", [ "?11=elf&12=zw%C3%B6lf", "?12=zw%C3%B6lf&11=elf", "?11=elf&12=zw%C3%83%C2%B6lf"] ] ] } } -- cgit v1.2.3 From 0a1cd6f8adf44f7cbe1717e4db44fec364f4e272 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 6 Dec 2019 11:11:57 -0800 Subject: Revert test input file changes --- tests/fixtures/extended-tests.json | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/fixtures/extended-tests.json b/tests/fixtures/extended-tests.json index 3fd88f9..ad43ad6 100644 --- a/tests/fixtures/extended-tests.json +++ b/tests/fixtures/extended-tests.json @@ -46,16 +46,10 @@ ["/base{/group_id,first_name}/pages{/page,lang}{?format,q}","/base/12345/John/pages/5/en?format=json&q=URI%20Templates"], ["/sparql{?query}", "/sparql?query=PREFIX%20dc%3A%20%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%20SELECT%20%3Fbook%20%3Fwho%20WHERE%20%7B%20%3Fbook%20dc%3Acreator%20%3Fwho%20%7D"], ["/go{?uri}", "/go?uri=http%3A%2F%2Fexample.org%2F%3Furi%3Dhttp%253A%252F%252Fexample.org%252F"], - ["/service{?word}", [ "/service?word=dr%C3%BCcken", "/service?word=dr%C3%83%C2%BCcken"]], - ["/lookup{?Stra%C3%9Fe}", ["/lookup?Stra%C3%9Fe=Gr%C3%BCner%20Weg", "/lookup?Stra%C3%9Fe=Gr%C3%83%C2%BCner%20Weg"]], - ["{random}", - [ "%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF", - "%C3%85%C2%A1%C3%83%C2%B6%C3%83%C2%A4%C3%85%C2%B8%C3%85%E2%80%9C%C3%83%C2%B1%C3%83%C2%AA%C3%A2%E2%80%9A%C2%AC%C3%82%C2%A3%C3%82%C2%A5%C3%A2%E2%82%AC%C2%A1%C3%83%E2%80%98%C3%83%E2%80%99%C3%83%E2%80%9C%C3%83%E2%80%9D%C3%83%E2%80%A2%C3%83%E2%80%93%C3%83%E2%80%94%C3%83%CB%9C%C3%83%E2%84%A2%C3%83%C5%A1%C3%83%C2%A0%C3%83%C2%A1%C3%83%C2%A2%C3%83%C2%A3%C3%83%C2%A4%C3%83%C2%A5%C3%83%C2%A6%C3%83%C2%A7%C3%83%C2%BF"] - ], - ["{?assoc_special_chars*}", - [ "?%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95=%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF", - "?%C3%85%C2%A1%C3%83%C2%B6%C3%83%C2%A4%C3%85%C2%B8%C3%85%E2%80%9C%C3%83%C2%B1%C3%83%C2%AA%C3%A2%E2%80%9A%C2%AC%C3%82%C2%A3%C3%82%C2%A5%C3%A2%E2%82%AC%C2%A1%C3%83%E2%80%98%C3%83%E2%80%99%C3%83%E2%80%9C%C3%83%E2%80%9D%C3%83%E2%80%A2=%C3%83%E2%80%93%C3%83%E2%80%94%C3%83%CB%9C%C3%83%E2%84%A2%C3%83%C5%A1%C3%83%C2%A0%C3%83%C2%A1%C3%83%C2%A2%C3%83%C2%A3%C3%83%C2%A4%C3%83%C2%A5%C3%83%C2%A6%C3%83%C2%A7%C3%83%C2%BF"] - ] + ["/service{?word}", "/service?word=dr%C3%BCcken"], + ["/lookup{?Stra%C3%9Fe}", "/lookup?Stra%C3%9Fe=Gr%C3%BCner%20Weg"], + ["{random}" , "%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF"], + ["{?assoc_special_chars*}", "?%C5%A1%C3%B6%C3%A4%C5%B8%C5%93%C3%B1%C3%AA%E2%82%AC%C2%A3%C2%A5%E2%80%A1%C3%91%C3%92%C3%93%C3%94%C3%95=%C3%96%C3%97%C3%98%C3%99%C3%9A%C3%A0%C3%A1%C3%A2%C3%A3%C3%A4%C3%A5%C3%A6%C3%A7%C3%BF"] ] }, "Additional Examples 2":{ @@ -118,7 +112,7 @@ [ "{?42}", "?42=The%20Answer%20to%20the%20Ultimate%20Question%20of%20Life%2C%20the%20Universe%2C%20and%20Everything"], [ "{1337}", "leet,as,it,can,be"], [ "{?1337*}", "?1337=leet&1337=as&1337=it&1337=can&1337=be"], - [ "{?german*}", [ "?11=elf&12=zw%C3%B6lf", "?12=zw%C3%B6lf&11=elf", "?11=elf&12=zw%C3%83%C2%B6lf"] ] + [ "{?german*}", [ "?11=elf&12=zw%C3%B6lf", "?12=zw%C3%B6lf&11=elf"] ] ] } } -- cgit v1.2.3 From 6ef7577baf8a99539d4c2e3965c4797c6ea5d318 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 6 Dec 2019 11:12:20 -0800 Subject: Specify file encodings --- tests/test_from_fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_from_fixtures.py b/tests/test_from_fixtures.py index c21d395..4b92081 100644 --- a/tests/test_from_fixtures.py +++ b/tests/test_from_fixtures.py @@ -12,7 +12,7 @@ def fixture_file_path(filename): def load_examples(filename): path = fixture_file_path(filename) - with open(path, 'r') as examples_file: + with open(path, 'r', encoding="utf-8") as examples_file: examples = json.load(examples_file) return examples -- cgit v1.2.3 From b98d77c546835aeded413cd7048e503f0158f387 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 6 Dec 2019 11:15:03 -0800 Subject: Appease Python 2.7 --- tests/test_from_fixtures.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_from_fixtures.py b/tests/test_from_fixtures.py index 4b92081..d6c9810 100644 --- a/tests/test_from_fixtures.py +++ b/tests/test_from_fixtures.py @@ -1,3 +1,4 @@ +import io import json import os.path @@ -12,7 +13,7 @@ def fixture_file_path(filename): def load_examples(filename): path = fixture_file_path(filename) - with open(path, 'r', encoding="utf-8") as examples_file: + with io.open(path, 'r', encoding="utf-8") as examples_file: examples = json.load(examples_file) return examples -- cgit v1.2.3