Skip to content

Commit 18afc90

Browse files
author
Sylvain MARIE
committed
Now using %r everywhere we used %s + repr()
1 parent aa0d551 commit 18afc90

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

valid8/common_syntax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ def make_validation_func_callables(*vf_definition, # type: OneO
193193
supported tuples to use.
194194
195195
>>> import sys, pytest
196-
>>> if sys.version_info < (3, 0):
197-
... pytest.skip('doctest skipped in python 2 because exception namespace is different but details matter')
196+
>>> if sys.version_info < (3, 6):
197+
... pytest.skip('doctest skipped for old python versions')
198198
199199
>>> # two dummy validation callables
200200
>>> def is_big(x): return x > 10

valid8/composition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ def get_details(self, compact_mode=False):
8686
raise ValueError("Internal error, this should not happen - please report")
8787

8888
# OrderedDict does not pretty print...
89-
key_values_str = [repr(key) + ': ' + repr(val) for key, val in failures_for_print.items()]
89+
key_values_str = ['%r: %r' % (key, val) for key, val in failures_for_print.items()]
9090
failures_str = '{' + ', '.join(key_values_str) + '}'
9191

9292
# Note: we do note cite the value in the message since it is most probably available in inner messages [{val}]
9393
what = self.get_what()
94-
possibly_value = "" if compact_mode else (" for value %s" % repr(self.wrong_value))
94+
possibly_value = "" if compact_mode else (" for value %r" % self.wrong_value)
9595
return '%s%s. Successes: %s / Failures: %s.' % (what, possibly_value, self.successes, failures_str)
9696

9797
def play_all_validators(self, validators, value, **ctx):

valid8/tests/readme/test_readme_index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_readme_usage_validator():
8383
v.alid = surf > 0
8484
e = exc_info.value
8585
assert str(e) == "Error validating [surface=1j]. " \
86-
"HasWrongType: Value should be an instance of %s. Wrong value: 1j." % repr(int)
86+
"HasWrongType: Value should be an instance of %r. Wrong value: 1j." % int
8787

8888
from valid8 import assert_instance_of
8989
with pytest.raises(ValidationError) as exc_info:
@@ -92,7 +92,7 @@ def test_readme_usage_validator():
9292
v.alid = surf > 0
9393
e = exc_info.value
9494
assert str(e) == "Error validating [surface=1j]. " \
95-
"HasWrongType: Value should be an instance of %s. Wrong value: 1j." % repr(int)
95+
"HasWrongType: Value should be an instance of %r. Wrong value: 1j." % int
9696

9797

9898
def test_readme_usage_customization():
@@ -199,8 +199,8 @@ def build_house(name, surface=None):
199199
assert str(e) == "name should be a non-empty string. " \
200200
"Error validating input [name=''] for function [build_house]. " \
201201
"At least one validation function failed for value ''. " \
202-
"Successes: [\"instance_of_%s\"] / Failures: {'len(s) > 0': 'Returned False.'}." \
203-
"" % (repr(str), )
202+
"Successes: [\"instance_of_%r\"] / Failures: {'len(s) > 0': 'Returned False.'}." \
203+
"" % str
204204

205205
from mini_lambda import s, x, l, Len
206206
from valid8 import validate_arg, validate_out

valid8/tests/readme/test_readme_usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def test_usage_validators():
194194
with pytest.raises(ValidationError) as exc_info:
195195
validate_is_superclass_of_bool('typ', str)
196196
e = exc_info.value
197-
assert str(e) == "Error validating [typ=%s]. InvalidValue: Function [%s] returned [False] for value %s." \
198-
"" % (repr(str), repr(_is_subclass_of_bool), repr(str))
197+
assert str(e) == "Error validating [typ=%r]. InvalidValue: Function [%r] returned [False] for value %r." \
198+
"" % (str, _is_subclass_of_bool, str)
199199

200200
validate_is_multiple_of_3('val', 21) # ok
201201
with pytest.raises(ValidationError) as exc_info:

valid8/tests/test_entry_points_inline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_validate_():
3535
validate('surface', surf, instance_of=(int, ), min_value=0)
3636
e = exc_info.value
3737
assert str(e) == "Error validating [surface=1j]. " \
38-
"HasWrongType: Value should be an instance of %s. Wrong value: 1j." % repr(int)
38+
"HasWrongType: Value should be an instance of %r. Wrong value: 1j." % int
3939

4040

4141
def test_readme_usage_validate__customization():
@@ -49,7 +49,7 @@ def test_readme_usage_validate__customization():
4949
help_msg="Surface should be a positive integer")
5050
e = exc_info.value
5151
assert str(e) == "Surface should be a positive integer. Error validating [surface=1j]. " \
52-
"HasWrongType: Value should be an instance of %s. Wrong value: 1j." % repr(int)
52+
"HasWrongType: Value should be an instance of %r. Wrong value: 1j." % int
5353

5454
# (B) custom error types (recommended to provide unique applicative errors)
5555
class InvalidSurface(ValidationError):
@@ -70,7 +70,7 @@ class InvalidSurface(ValidationError):
7070
e = exc_info.value
7171
assert isinstance(e, InvalidSurface)
7272
assert str(e) == "Surface should be > 0, found 1j. Error validating [surface=1j]. " \
73-
"HasWrongType: Value should be an instance of %s. Wrong value: 1j." % repr(int)
73+
"HasWrongType: Value should be an instance of %r. Wrong value: 1j." % int
7474

7575

7676
def test_validator_context_manager():

0 commit comments

Comments
 (0)