aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <sigmavirus24@users.noreply.github.com>2015-11-13 08:24:32 -0600
committerIan Cordasco <sigmavirus24@users.noreply.github.com>2015-11-13 08:24:32 -0600
commit16d9beae04c55e3edffd76d17599a0b2a0be93dd (patch)
treefc6a768135d2ed214f80588a359bc0af8711adfe
parent995f88f79a4881df48af3e230c5ed9321176d071 (diff)
parent544b80322d5d914f1a4112ee436ad8e4050135b3 (diff)
downloaduritemplates-16d9beae04c55e3edffd76d17599a0b2a0be93dd.tar.gz
Merge pull request #20 from dwieeb/master
Fix for #17
-rw-r--r--tests/test_from_fixtures.py3
-rw-r--r--tox.ini2
-rw-r--r--uritemplate/variable.py17
3 files changed, 12 insertions, 10 deletions
diff --git a/tests/test_from_fixtures.py b/tests/test_from_fixtures.py
index 0c23cc3..0ecc075 100644
--- a/tests/test_from_fixtures.py
+++ b/tests/test_from_fixtures.py
@@ -102,7 +102,8 @@ class TestSpecExamplesByRFCSection(FixtureMixin):
class TestExtendedTests(FixtureMixin):
examples = load_examples('extended-tests')
- @pytest.mark.xfail(reason='See bug #17')
+ @pytest.mark.xfail(sys.version_info < (3, 0),
+ reason='See bug #19')
def test_additional_examples_1(self):
"""Check Additional Examples 1."""
self._test('Additional Examples 1')
diff --git a/tox.ini b/tox.ini
index e15543c..b81521a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -11,7 +11,7 @@ envlist =
[testenv]
deps =
pytest
-commands = py.test
+commands = py.test {posargs}
[testenv:pep8]
deps =
diff --git a/uritemplate/variable.py b/uritemplate/variable.py
index a17c2e1..2f6dbd9 100644
--- a/uritemplate/variable.py
+++ b/uritemplate/variable.py
@@ -137,13 +137,15 @@ class URIVariable(object):
def _query_expansion(self, name, value, explode, prefix):
"""Expansion method for the '?' and '&' operators."""
- if value is None or (len(value) == 0 and value != ""):
+ if value is None:
return None
tuples, items = is_list_of_tuples(value)
safe = self.safe
if list_test(value) and not tuples:
+ if not value:
+ return None
if explode:
return self.join_str.join(
'%s=%s' % (name, quote(v, safe)) for v in value
@@ -153,6 +155,8 @@ class URIVariable(object):
return '%s=%s' % (name, value)
if dict_test(value) or tuples:
+ if not value:
+ return None
items = items or sorted(value.items())
if explode:
return self.join_str.join(
@@ -170,7 +174,7 @@ class URIVariable(object):
if value:
value = value[:prefix] if prefix else value
- return '%s=%s' % (name, quote(value, safe))
+ return '%s=%s' % (name, quote(str(value), safe))
return name + '='
def _label_path_expansion(self, name, value, explode, prefix):
@@ -342,14 +346,11 @@ class URIVariable(object):
def is_list_of_tuples(value):
- if not isinstance(value, (list, tuple)):
+ if not value or not isinstance(value, (list, tuple)) or \
+ not all(isinstance(t, tuple) and len(t) == 2 for t in value):
return False, None
- try:
- dict(value)
- return True, value
- except:
- return False, None
+ return True, value
def list_test(value):