Accepting request 817235 from devel:languages:python

OBS-URL: https://build.opensuse.org/request/show/817235
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-voluptuous?expand=0&rev=7
This commit is contained in:
Dominique Leuenberger 2020-06-28 21:05:12 +00:00 committed by Git OBS Bridge
commit c3c8008ee8
3 changed files with 952 additions and 3 deletions

View File

@ -0,0 +1,939 @@
Index: voluptuous-0.11.7/voluptuous/tests/tests.py
===================================================================
--- voluptuous-0.11.7.orig/voluptuous/tests/tests.py 2019-08-13 04:10:58.000000000 +0200
+++ voluptuous-0.11.7/voluptuous/tests/tests.py 2020-06-26 09:09:03.136465644 +0200
@@ -2,8 +2,7 @@ import copy
import collections
import os
import sys
-
-from nose.tools import assert_equal, assert_false, assert_raises, assert_true
+import pytest
from voluptuous import (
Schema, Required, Exclusive, Inclusive, Optional, Extra, Invalid, In, Remove,
@@ -24,18 +23,16 @@ def test_exact_sequence():
assert True
else:
assert False, "Did not raise Invalid"
- assert_equal(schema([1, 2]), [1, 2])
+ assert schema([1, 2]) == [1, 2]
def test_required():
"""Verify that Required works."""
schema = Schema({Required('q'): 1})
- # Can't use nose's raises (because we need to access the raised
- # exception, nor assert_raises which fails with Python 2.6.9.
try:
schema({})
except Invalid as e:
- assert_equal(str(e), "required key not provided @ data['q']")
+ assert str(e) == "required key not provided @ data['q']"
else:
assert False, "Did not raise Invalid"
@@ -44,8 +41,7 @@ def test_extra_with_required():
"""Verify that Required does not break Extra."""
schema = Schema({Required('toaster'): str, Extra: object})
r = schema({'toaster': 'blue', 'another_valid_key': 'another_valid_value'})
- assert_equal(
- r, {'toaster': 'blue', 'another_valid_key': 'another_valid_value'})
+ assert r == {'toaster': 'blue', 'another_valid_key': 'another_valid_value'}
def test_iterate_candidates():
@@ -56,7 +52,7 @@ def test_iterate_candidates():
}
# toaster should be first.
from voluptuous.schema_builder import _iterate_mapping_candidates
- assert_equal(_iterate_mapping_candidates(schema)[0][0], 'toaster')
+ assert _iterate_mapping_candidates(schema)[0][0] == 'toaster'
def test_in():
@@ -72,7 +68,7 @@ def test_not_in():
try:
schema({"color": "blue"})
except Invalid as e:
- assert_equal(str(e), "value is not allowed for dictionary value @ data['color']")
+ assert str(e) == "value is not allowed for dictionary value @ data['color']"
else:
assert False, "Did not raise NotInInvalid"
@@ -84,8 +80,7 @@ def test_contains():
try:
schema({'color': ['blue', 'yellow']})
except Invalid as e:
- assert_equal(str(e),
- "value is not allowed for dictionary value @ data['color']")
+ assert str(e) == "value is not allowed for dictionary value @ data['color']"
def test_remove():
@@ -117,12 +112,12 @@ def test_remove():
# remove value from list
schema = Schema([Remove(1), int])
out_ = schema([1, 2, 3, 4, 1, 5, 6, 1, 1, 1])
- assert_equal(out_, [2, 3, 4, 5, 6])
+ assert out_ == [2, 3, 4, 5, 6]
# remove values from list by type
schema = Schema([1.0, Remove(float), int])
out_ = schema([1, 2, 1.0, 2.0, 3.0, 4])
- assert_equal(out_, [1, 2, 1.0, 4])
+ assert out_ == [1, 2, 1.0, 4]
def test_extra_empty_errors():
@@ -141,7 +136,7 @@ def test_literal():
try:
schema([{"c": 1}])
except Invalid as e:
- assert_equal(str(e), "{'c': 1} not match for {'b': 1} @ data[0]")
+ assert str(e) == "{'c': 1} not match for {'b': 1} @ data[0]"
else:
assert False, "Did not raise Invalid"
@@ -149,9 +144,9 @@ def test_literal():
try:
schema({"b": 1})
except MultipleInvalid as e:
- assert_equal(str(e), "{'b': 1} not match for {'a': 1}")
- assert_equal(len(e.errors), 1)
- assert_equal(type(e.errors[0]), LiteralInvalid)
+ assert str(e) == "{'b': 1} not match for {'a': 1}"
+ assert len(e.errors) == 1
+ assert type(e.errors[0]) == LiteralInvalid
else:
assert False, "Did not raise Invalid"
@@ -166,9 +161,9 @@ def test_class():
try:
schema(None)
except MultipleInvalid as e:
- assert_equal(str(e), "expected C1")
- assert_equal(len(e.errors), 1)
- assert_equal(type(e.errors[0]), TypeInvalid)
+ assert str(e) == "expected C1"
+ assert len(e.errors) == 1
+ assert type(e.errors[0]) == TypeInvalid
else:
assert False, "Did not raise Invalid"
@@ -182,9 +177,9 @@ def test_class():
try:
schema(None)
except MultipleInvalid as e:
- assert_equal(str(e), "expected C2")
- assert_equal(len(e.errors), 1)
- assert_equal(type(e.errors[0]), TypeInvalid)
+ assert str(e) == "expected C2"
+ assert len(e.errors) == 1
+ assert type(e.errors[0]) == TypeInvalid
else:
assert False, "Did not raise Invalid"
@@ -203,8 +198,7 @@ def test_email_validation_with_none():
try:
schema({"email": None})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected an Email for dictionary value @ data['email']")
+ assert str(e) == "expected an Email for dictionary value @ data['email']"
else:
assert False, "Did not raise Invalid for None url"
@@ -215,8 +209,7 @@ def test_email_validation_with_empty_str
try:
schema({"email": ''})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected an Email for dictionary value @ data['email']")
+ assert str(e) == "expected an Email for dictionary value @ data['email']"
else:
assert False, "Did not raise Invalid for empty string url"
@@ -227,8 +220,7 @@ def test_email_validation_without_host()
try:
schema({"email": 'a@.com'})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected an Email for dictionary value @ data['email']")
+ assert str(e) == "expected an Email for dictionary value @ data['email']"
else:
assert False, "Did not raise Invalid for empty string url"
@@ -247,8 +239,7 @@ def test_fqdn_url_without_domain_name():
try:
schema({"url": "http://localhost/"})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected a Fully qualified domain name URL for dictionary value @ data['url']")
+ assert str(e) == "expected a Fully qualified domain name URL for dictionary value @ data['url']"
else:
assert False, "Did not raise Invalid for None url"
@@ -259,8 +250,7 @@ def test_fqdnurl_validation_with_none():
try:
schema({"url": None})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected a Fully qualified domain name URL for dictionary value @ data['url']")
+ assert str(e) == "expected a Fully qualified domain name URL for dictionary value @ data['url']"
else:
assert False, "Did not raise Invalid for None url"
@@ -271,8 +261,7 @@ def test_fqdnurl_validation_with_empty_s
try:
schema({"url": ''})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected a Fully qualified domain name URL for dictionary value @ data['url']")
+ assert str(e) == "expected a Fully qualified domain name URL for dictionary value @ data['url']"
else:
assert False, "Did not raise Invalid for empty string url"
@@ -283,8 +272,7 @@ def test_fqdnurl_validation_without_host
try:
schema({"url": 'http://'})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected a Fully qualified domain name URL for dictionary value @ data['url']")
+ assert str(e) == "expected a Fully qualified domain name URL for dictionary value @ data['url']"
else:
assert False, "Did not raise Invalid for empty string url"
@@ -303,8 +291,7 @@ def test_url_validation_with_none():
try:
schema({"url": None})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected a URL for dictionary value @ data['url']")
+ assert str(e) == "expected a URL for dictionary value @ data['url']"
else:
assert False, "Did not raise Invalid for None url"
@@ -315,8 +302,7 @@ def test_url_validation_with_empty_strin
try:
schema({"url": ''})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected a URL for dictionary value @ data['url']")
+ assert str(e) == "expected a URL for dictionary value @ data['url']"
else:
assert False, "Did not raise Invalid for empty string url"
@@ -327,8 +313,7 @@ def test_url_validation_without_host():
try:
schema({"url": 'http://'})
except MultipleInvalid as e:
- assert_equal(str(e),
- "expected a URL for dictionary value @ data['url']")
+ assert str(e) == "expected a URL for dictionary value @ data['url']"
else:
assert False, "Did not raise Invalid for empty string url"
@@ -394,10 +379,10 @@ def test_schema_extend_key_swap():
extension = {Required('a'): int}
extended = base.extend(extension)
- assert_equal(len(base.schema), 1)
- assert_true(isinstance(list(base.schema)[0], Optional))
- assert_equal(len(extended.schema), 1)
- assert_true((list(extended.schema)[0], Required))
+ assert len(base.schema) == 1
+ assert isinstance(list(base.schema)[0], Optional)
+ assert len(extended.schema) == 1
+ assert (list(extended.schema)[0], Required)
def test_subschema_extension():
@@ -407,9 +392,9 @@ def test_subschema_extension():
extension = {'d': str, 'a': {'b': str, 'e': int}}
extended = base.extend(extension)
- assert_equal(base.schema, {'a': {'b': int, 'c': float}})
- assert_equal(extension, {'d': str, 'a': {'b': str, 'e': int}})
- assert_equal(extended.schema, {'a': {'b': str, 'c': float, 'e': int}, 'd': str})
+ assert base.schema == {'a': {'b': int, 'c': float}}
+ assert extension == {'d': str, 'a': {'b': str, 'e': int}}
+ assert extended.schema == {'a': {'b': str, 'c': float, 'e': int}, 'd': str}
def test_schema_extend_handles_schema_subclass():
@@ -427,10 +412,9 @@ def test_schema_extend_handles_schema_su
def test_equality():
- assert_equal(Schema('foo'), Schema('foo'))
+ assert Schema('foo') == Schema('foo')
- assert_equal(Schema(['foo', 'bar', 'baz']),
- Schema(['foo', 'bar', 'baz']))
+ assert Schema(['foo', 'bar', 'baz']) == Schema(['foo', 'bar', 'baz'])
# Ensure two Schemas w/ two equivalent dicts initialized in a different
# order are considered equal.
@@ -444,35 +428,34 @@ def test_equality():
dict_b['bar'] = 2
dict_b['foo'] = 1
- assert_equal(Schema(dict_a), Schema(dict_b))
+ assert Schema(dict_a) == Schema(dict_b)
def test_equality_negative():
"""Verify that Schema objects are not equal to string representations"""
- assert_false(Schema('foo') == 'foo')
+ assert not Schema('foo') == 'foo'
- assert_false(Schema(['foo', 'bar']) == "['foo', 'bar']")
- assert_false(Schema(['foo', 'bar']) == Schema("['foo', 'bar']"))
+ assert not Schema(['foo', 'bar']) == "['foo', 'bar']"
+ assert not Schema(['foo', 'bar']) == Schema("['foo', 'bar']")
- assert_false(Schema({'foo': 1, 'bar': 2}) == "{'foo': 1, 'bar': 2}")
- assert_false(Schema({'foo': 1, 'bar': 2}) == Schema("{'foo': 1, 'bar': 2}"))
+ assert not Schema({'foo': 1, 'bar': 2}) == "{'foo': 1, 'bar': 2}"
+ assert not Schema({'foo': 1, 'bar': 2}) == Schema("{'foo': 1, 'bar': 2}")
def test_inequality():
- assert_true(Schema('foo') != 'foo')
+ assert Schema('foo') != 'foo'
- assert_true(Schema(['foo', 'bar']) != "['foo', 'bar']")
- assert_true(Schema(['foo', 'bar']) != Schema("['foo', 'bar']"))
+ assert Schema(['foo', 'bar']) != "['foo', 'bar']"
+ assert Schema(['foo', 'bar']) != Schema("['foo', 'bar']")
- assert_true(Schema({'foo': 1, 'bar': 2}) != "{'foo': 1, 'bar': 2}")
- assert_true(Schema({'foo': 1, 'bar': 2}) != Schema("{'foo': 1, 'bar': 2}"))
+ assert Schema({'foo': 1, 'bar': 2}) != "{'foo': 1, 'bar': 2}"
+ assert Schema({'foo': 1, 'bar': 2}) != Schema("{'foo': 1, 'bar': 2}")
def test_inequality_negative():
- assert_false(Schema('foo') != Schema('foo'))
+ assert not Schema('foo') != Schema('foo')
- assert_false(Schema(['foo', 'bar', 'baz']) !=
- Schema(['foo', 'bar', 'baz']))
+ assert not Schema(['foo', 'bar', 'baz']) != Schema(['foo', 'bar', 'baz'])
# Ensure two Schemas w/ two equivalent dicts initialized in a different
# order are considered equal.
@@ -486,7 +469,7 @@ def test_inequality_negative():
dict_b['bar'] = 2
dict_b['foo'] = 1
- assert_false(Schema(dict_a) != Schema(dict_b))
+ assert not Schema(dict_a) != Schema(dict_b)
def test_repr():
@@ -499,15 +482,12 @@ def test_repr():
all_ = All('10', Coerce(int), msg='all msg')
maybe_int = Maybe(int)
- assert_equal(repr(match), "Match('a pattern', msg='message')")
- assert_equal(repr(replace), "Replace('you', 'I', msg='you and I')")
- assert_equal(
- repr(range_),
- "Range(min=0, max=42, min_included=False, max_included=False, msg='number not in range')"
- )
- assert_equal(repr(coerce_), "Coerce(int, msg='moo')")
- assert_equal(repr(all_), "All('10', Coerce(int, msg=None), msg='all msg')")
- assert_equal(repr(maybe_int), "Any(None, %s, msg=None)" % str(int))
+ assert repr(match) == "Match('a pattern', msg='message')"
+ assert repr(replace) == "Replace('you', 'I', msg='you and I')"
+ assert repr(range_) == "Range(min=0, max=42, min_included=False, max_included=False, msg='number not in range')"
+ assert repr(coerce_) == "Coerce(int, msg='moo')"
+ assert repr(all_) == "All('10', Coerce(int, msg=None), msg='all msg')"
+ assert repr(maybe_int) == "Any(None, %s, msg=None)" % str(int)
def test_list_validation_messages():
@@ -523,9 +503,9 @@ def test_list_validation_messages():
try:
schema(dict(even_numbers=[3]))
except Invalid as e:
- assert_equal(len(e.errors), 1, e.errors)
- assert_equal(str(e.errors[0]), "3 is not even @ data['even_numbers'][0]")
- assert_equal(str(e), "3 is not even @ data['even_numbers'][0]")
+ assert len(e.errors) == 1
+ assert str(e.errors[0]) == "3 is not even @ data['even_numbers'][0]"
+ assert str(e) == "3 is not even @ data['even_numbers'][0]"
else:
assert False, "Did not raise Invalid"
@@ -544,9 +524,9 @@ def test_nested_multiple_validation_erro
try:
schema(dict(even_numbers=[3]))
except Invalid as e:
- assert_equal(len(e.errors), 1, e.errors)
- assert_equal(str(e.errors[0]), "3 is not even @ data['even_numbers'][0]")
- assert_equal(str(e), "3 is not even @ data['even_numbers'][0]")
+ assert len(e.errors) == 1
+ assert str(e.errors[0]) == "3 is not even @ data['even_numbers'][0]"
+ assert str(e) == "3 is not even @ data['even_numbers'][0]"
else:
assert False, "Did not raise Invalid"
@@ -563,40 +543,36 @@ def test_humanize_error():
try:
schema(data)
except MultipleInvalid as e:
- assert_equal(
- humanize_error(data, e),
- "expected int for dictionary value @ data['a']. Got 'not an int'\n"
- "expected str @ data['b'][0]. Got 123"
- )
+ assert humanize_error(data, e) == "expected int for dictionary value @ data['a']. Got 'not an int'\nexpected str @ data['b'][0]. Got 123"
else:
assert False, 'Did not raise MultipleInvalid'
def test_fix_157():
s = Schema(All([Any('one', 'two', 'three')]), Length(min=1))
- assert_equal(['one'], s(['one']))
- assert_raises(MultipleInvalid, s, ['four'])
+ assert ['one'] == s(['one'])
+ pytest.raises(MultipleInvalid, s, ['four'])
def test_range_exlcudes_nan():
s = Schema(Range(min=0, max=10))
- assert_raises(MultipleInvalid, s, float('nan'))
+ pytest.raises(MultipleInvalid, s, float('nan'))
def test_equal():
s = Schema(Equal(1))
s(1)
- assert_raises(Invalid, s, 2)
+ pytest.raises(Invalid, s, 2)
s = Schema(Equal('foo'))
s('foo')
- assert_raises(Invalid, s, 'bar')
+ pytest.raises(Invalid, s, 'bar')
s = Schema(Equal([1, 2]))
s([1, 2])
- assert_raises(Invalid, s, [])
- assert_raises(Invalid, s, [1, 2, 3])
+ pytest.raises(Invalid, s, [])
+ pytest.raises(Invalid, s, [1, 2, 3])
# Evaluates exactly, not through validators
s = Schema(Equal(str))
- assert_raises(Invalid, s, 'foo')
+ pytest.raises(Invalid, s, 'foo')
def test_unordered():
@@ -605,15 +581,15 @@ def test_unordered():
s([2, 1])
s([1, 2])
# Amount of errors is OK
- assert_raises(Invalid, s, [2, 0])
- assert_raises(MultipleInvalid, s, [0, 0])
+ pytest.raises(Invalid, s, [2, 0])
+ pytest.raises(MultipleInvalid, s, [0, 0])
# Different length is NOK
- assert_raises(Invalid, s, [1])
- assert_raises(Invalid, s, [1, 2, 0])
- assert_raises(MultipleInvalid, s, [1, 2, 0, 0])
+ pytest.raises(Invalid, s, [1])
+ pytest.raises(Invalid, s, [1, 2, 0])
+ pytest.raises(MultipleInvalid, s, [1, 2, 0, 0])
# Other type than list or tuple is NOK
- assert_raises(Invalid, s, 'foo')
- assert_raises(Invalid, s, 10)
+ pytest.raises(Invalid, s, 'foo')
+ pytest.raises(Invalid, s, 10)
# Validators are evaluated through as schemas
s = Schema(Unordered([int, str]))
s([1, '2'])
@@ -622,7 +598,7 @@ def test_unordered():
s([{'foo': 3}, []])
# Most accurate validators must be positioned on left
s = Schema(Unordered([int, 3]))
- assert_raises(Invalid, s, [3, 2])
+ pytest.raises(Invalid, s, [3, 2])
s = Schema(Unordered([3, int]))
s([3, 2])
@@ -631,12 +607,12 @@ def test_maybe():
s = Schema(Maybe(int))
assert s(1) == 1
assert s(None) is None
- assert_raises(Invalid, s, 'foo')
+ pytest.raises(Invalid, s, 'foo')
s = Schema(Maybe({str: Coerce(int)}))
assert s({'foo': '100'}) == {'foo': 100}
assert s(None) is None
- assert_raises(Invalid, s, {'foo': 'bar'})
+ pytest.raises(Invalid, s, {'foo': 'bar'})
def test_maybe_accepts_msg():
@@ -647,7 +623,7 @@ def test_maybe_accepts_msg():
def test_empty_list_as_exact():
s = Schema([])
- assert_raises(Invalid, s, [1])
+ pytest.raises(Invalid, s, [1])
s([])
@@ -664,7 +640,7 @@ def test_schema_decorator_unmatch_with_a
def fn(arg):
return arg
- assert_raises(Invalid, fn, 1.0)
+ pytest.raises(Invalid, fn, 1.0)
def test_schema_decorator_match_with_kwargs():
@@ -680,7 +656,7 @@ def test_schema_decorator_unmatch_with_k
def fn(arg):
return arg
- assert_raises(Invalid, fn, 1.0)
+ pytest.raises(Invalid, fn, 1.0)
def test_schema_decorator_match_return_with_args():
@@ -696,7 +672,7 @@ def test_schema_decorator_unmatch_return
def fn(arg):
return "hello"
- assert_raises(Invalid, fn, 1)
+ pytest.raises(Invalid, fn, 1)
def test_schema_decorator_match_return_with_kwargs():
@@ -712,7 +688,7 @@ def test_schema_decorator_unmatch_return
def fn(arg):
return "hello"
- assert_raises(Invalid, fn, 1)
+ pytest.raises(Invalid, fn, 1)
def test_schema_decorator_return_only_match():
@@ -728,7 +704,7 @@ def test_schema_decorator_return_only_un
def fn(arg):
return "hello"
- assert_raises(Invalid, fn, 1)
+ pytest.raises(Invalid, fn, 1)
def test_schema_decorator_partial_match_called_with_args():
@@ -744,7 +720,7 @@ def test_schema_decorator_partial_unmatc
def fn(arg1, arg2):
return arg1
- assert_raises(Invalid, fn, "bar", "foo")
+ pytest.raises(Invalid, fn, "bar", "foo")
def test_schema_decorator_partial_match_called_with_kwargs():
@@ -760,7 +736,7 @@ def test_schema_decorator_partial_unmatc
def fn(arg1, arg2):
return arg1
- assert_raises(Invalid, fn, arg1=1, arg2="foo")
+ pytest.raises(Invalid, fn, arg1=1, arg2="foo")
def test_unicode_as_key():
@@ -778,8 +754,7 @@ def test_number_validation_with_string()
try:
schema({"number": 'teststr'})
except MultipleInvalid as e:
- assert_equal(str(e),
- "Value must be a number enclosed with string for dictionary value @ data['number']")
+ assert str(e) == "Value must be a number enclosed with string for dictionary value @ data['number']"
else:
assert False, "Did not raise Invalid for String"
@@ -790,8 +765,7 @@ def test_number_validation_with_invalid_
try:
schema({"number": '123456.712'})
except MultipleInvalid as e:
- assert_equal(str(e),
- "Precision must be equal to 6, and Scale must be equal to 2 for dictionary value @ data['number']")
+ assert str(e) == "Precision must be equal to 6, and Scale must be equal to 2 for dictionary value @ data['number']"
else:
assert False, "Did not raise Invalid for String"
@@ -800,28 +774,28 @@ def test_number_validation_with_valid_pr
""" test with Number with valid precision and scale"""
schema = Schema({"number": Number(precision=6, scale=2, yield_decimal=True)})
out_ = schema({"number": '1234.00'})
- assert_equal(float(out_.get("number")), 1234.00)
+ assert float(out_.get("number")) == 1234.00
def test_number_when_precision_scale_none_yield_decimal_true():
""" test with Number with no precision and scale"""
schema = Schema({"number": Number(yield_decimal=True)})
out_ = schema({"number": '12345678901234'})
- assert_equal(out_.get("number"), 12345678901234)
+ assert out_.get("number") == 12345678901234
def test_number_when_precision_none_n_valid_scale_case1_yield_decimal_true():
""" test with Number with no precision and valid scale case 1"""
schema = Schema({"number": Number(scale=2, yield_decimal=True)})
out_ = schema({"number": '123456789.34'})
- assert_equal(float(out_.get("number")), 123456789.34)
+ assert float(out_.get("number")) == 123456789.34
def test_number_when_precision_none_n_valid_scale_case2_yield_decimal_true():
""" test with Number with no precision and valid scale case 2 with zero in decimal part"""
schema = Schema({"number": Number(scale=2, yield_decimal=True)})
out_ = schema({"number": '123456789012.00'})
- assert_equal(float(out_.get("number")), 123456789012.00)
+ assert float(out_.get("number")) == 123456789012.00
def test_number_when_precision_none_n_invalid_scale_yield_decimal_true():
@@ -830,8 +804,7 @@ def test_number_when_precision_none_n_in
try:
schema({"number": '12345678901.234'})
except MultipleInvalid as e:
- assert_equal(str(e),
- "Scale must be equal to 2 for dictionary value @ data['number']")
+ assert str(e) == "Scale must be equal to 2 for dictionary value @ data['number']"
else:
assert False, "Did not raise Invalid for String"
@@ -840,7 +813,7 @@ def test_number_when_valid_precision_n_s
""" test with Number with no precision and valid scale"""
schema = Schema({"number": Number(precision=14, yield_decimal=True)})
out_ = schema({"number": '1234567.8901234'})
- assert_equal(float(out_.get("number")), 1234567.8901234)
+ assert float(out_.get("number")) == 1234567.8901234
def test_number_when_invalid_precision_n_scale_none_yield_decimal_true():
@@ -849,8 +822,7 @@ def test_number_when_invalid_precision_n
try:
schema({"number": '12345674.8901234'})
except MultipleInvalid as e:
- assert_equal(str(e),
- "Precision must be equal to 14 for dictionary value @ data['number']")
+ assert str(e) == "Precision must be equal to 14 for dictionary value @ data['number']"
else:
assert False, "Did not raise Invalid for String"
@@ -859,7 +831,7 @@ def test_number_validation_with_valid_pr
""" test with Number with valid precision, scale and no yield_decimal"""
schema = Schema({"number": Number(precision=6, scale=2, yield_decimal=False)})
out_ = schema({"number": '1234.00'})
- assert_equal(out_.get("number"), '1234.00')
+ assert out_.get("number") == '1234.00'
def test_named_tuples_validate_as_tuples():
@@ -876,19 +848,19 @@ def test_named_tuples_validate_as_tuples
def test_datetime():
schema = Schema({"datetime": Datetime()})
schema({"datetime": "2016-10-24T14:01:57.102152Z"})
- assert_raises(MultipleInvalid, schema, {"datetime": "2016-10-24T14:01:57"})
+ pytest.raises(MultipleInvalid, schema, {"datetime": "2016-10-24T14:01:57"})
def test_date():
schema = Schema({"date": Date()})
schema({"date": "2016-10-24"})
- assert_raises(MultipleInvalid, schema, {"date": "2016-10-24Z"})
+ pytest.raises(MultipleInvalid, schema, {"date": "2016-10-24Z"})
def test_date_custom_format():
schema = Schema({"date": Date("%Y%m%d")})
schema({"date": "20161024"})
- assert_raises(MultipleInvalid, schema, {"date": "2016-10-24"})
+ pytest.raises(MultipleInvalid, schema, {"date": "2016-10-24"})
def test_ordered_dict():
@@ -910,12 +882,12 @@ def test_marker_hashable():
Required('x'): int, Optional('y'): float,
Remove('j'): int, Remove(int): str, int: int
}
- assert_equal(definition.get('x'), int)
- assert_equal(definition.get('y'), float)
- assert_true(Required('x') == Required('x'))
- assert_true(Required('x') != Required('y'))
+ assert definition.get('x') == int
+ assert definition.get('y') == float
+ assert Required('x') == Required('x')
+ assert Required('x') != Required('y')
# Remove markers are not hashable
- assert_equal(definition.get('j'), None)
+ assert definition.get('j') == None
def test_schema_infer():
@@ -925,12 +897,12 @@ def test_schema_infer():
'int': 42,
'float': 3.14
})
- assert_equal(schema, Schema({
+ assert schema == Schema({
Required('str'): str,
Required('bool'): bool,
Required('int'): int,
Required('float'): float
- }))
+ })
def test_schema_infer_dict():
@@ -942,13 +914,13 @@ def test_schema_infer_dict():
}
})
- assert_equal(schema, Schema({
+ assert schema == Schema({
Required('a'): {
Required('b'): {
Required('c'): str
}
}
- }))
+ })
def test_schema_infer_list():
@@ -956,18 +928,18 @@ def test_schema_infer_list():
'list': ['foo', True, 42, 3.14]
})
- assert_equal(schema, Schema({
+ assert schema == Schema({
Required('list'): [str, bool, int, float]
- }))
+ })
def test_schema_infer_scalar():
- assert_equal(Schema.infer('foo'), Schema(str))
- assert_equal(Schema.infer(True), Schema(bool))
- assert_equal(Schema.infer(42), Schema(int))
- assert_equal(Schema.infer(3.14), Schema(float))
- assert_equal(Schema.infer({}), Schema(dict))
- assert_equal(Schema.infer([]), Schema(list))
+ assert Schema.infer('foo') == Schema(str)
+ assert Schema.infer(True) == Schema(bool)
+ assert Schema.infer(42) == Schema(int)
+ assert Schema.infer(3.14) == Schema(float)
+ assert Schema.infer({}) == Schema(dict)
+ assert Schema.infer([]) == Schema(list)
def test_schema_infer_accepts_kwargs():
@@ -1030,19 +1002,19 @@ def test_validation_performance():
def test_IsDir():
schema = Schema(IsDir())
- assert_raises(MultipleInvalid, schema, 3)
+ pytest.raises(MultipleInvalid, schema, 3)
schema(os.path.dirname(os.path.abspath(__file__)))
def test_IsFile():
schema = Schema(IsFile())
- assert_raises(MultipleInvalid, schema, 3)
+ pytest.raises(MultipleInvalid, schema, 3)
schema(os.path.abspath(__file__))
def test_PathExists():
schema = Schema(PathExists())
- assert_raises(MultipleInvalid, schema, 3)
+ pytest.raises(MultipleInvalid, schema, 3)
schema(os.path.abspath(__file__))
@@ -1216,7 +1188,7 @@ def test_SomeOf_on_bounds_assertion():
def test_comparing_voluptuous_object_to_str():
- assert_true(Optional('Classification') < 'Name')
+ assert Optional('Classification') < 'Name'
def test_set_of_integers():
@@ -1232,7 +1204,7 @@ def test_set_of_integers():
try:
schema(set(['abc']))
except MultipleInvalid as e:
- assert_equal(str(e), "invalid value in set")
+ assert str(e) == "invalid value in set"
else:
assert False, "Did not raise Invalid"
@@ -1250,7 +1222,7 @@ def test_frozenset_of_integers():
try:
schema(frozenset(['abc']))
except MultipleInvalid as e:
- assert_equal(str(e), "invalid value in frozenset")
+ assert str(e) == "invalid value in frozenset"
else:
assert False, "Did not raise Invalid"
@@ -1267,7 +1239,7 @@ def test_set_of_integers_and_strings():
try:
schema(set([None]))
except MultipleInvalid as e:
- assert_equal(str(e), "invalid value in set")
+ assert str(e) == "invalid value in set"
else:
assert False, "Did not raise Invalid"
@@ -1284,7 +1256,7 @@ def test_frozenset_of_integers_and_strin
try:
schema(frozenset([None]))
except MultipleInvalid as e:
- assert_equal(str(e), "invalid value in frozenset")
+ assert str(e) == "invalid value in frozenset"
else:
assert False, "Did not raise Invalid"
@@ -1330,8 +1302,7 @@ def test_any_required():
try:
schema({})
except MultipleInvalid as e:
- assert_equal(str(e),
- "required key not provided @ data['a']")
+ assert str(e) == "required key not provided @ data['a']"
else:
assert False, "Did not raise Invalid for MultipleInvalid"
@@ -1345,8 +1316,7 @@ def test_any_required_with_subschema():
try:
schema({})
except MultipleInvalid as e:
- assert_equal(str(e),
- "required key not provided @ data['a']")
+ assert str(e) == "required key not provided @ data['a']"
else:
assert False, "Did not raise Invalid for MultipleInvalid"
@@ -1357,16 +1327,15 @@ def test_inclusive():
})
r = schema({})
- assert_equal(r, {})
+ assert r == {}
r = schema({'x':1, 'y':2})
- assert_equal(r, {'x':1, 'y':2})
+ assert r == {'x':1, 'y':2}
try:
r = schema({'x':1})
except MultipleInvalid as e:
- assert_equal(str(e),
- "some but not all values in the same group of inclusion 'stuff' @ data[<stuff>]")
+ assert str(e) == "some but not all values in the same group of inclusion 'stuff' @ data[<stuff>]"
else:
assert False, "Did not raise Invalid for incomplete Inclusive group"
@@ -1377,13 +1346,12 @@ def test_inclusive_defaults():
})
r = schema({})
- assert_equal(r, {'x':3, 'y':4})
+ assert r == {'x':3, 'y':4}
try:
r = schema({'x':1})
except MultipleInvalid as e:
- assert_equal(str(e),
- "some but not all values in the same group of inclusion 'stuff' @ data[<stuff>]")
+ assert str(e) == "some but not all values in the same group of inclusion 'stuff' @ data[<stuff>]"
else:
assert False, "Did not raise Invalid for incomplete Inclusive group with defaults"
@@ -1394,15 +1362,14 @@ def test_exclusive():
})
r = schema({})
- assert_equal(r, {})
+ assert r == {}
r = schema({'x':1})
- assert_equal(r, {'x':1})
+ assert r == {'x':1}
try:
r = schema({'x':1, 'y': 2})
except MultipleInvalid as e:
- assert_equal(str(e),
- "two or more values in the same group of exclusion 'stuff' @ data[<stuff>]")
+ assert str(e) == "two or more values in the same group of exclusion 'stuff' @ data[<stuff>]"
else:
assert False, "Did not raise Invalid for multiple values in Exclusive group"
Index: voluptuous-0.11.7/PKG-INFO
===================================================================
--- voluptuous-0.11.7.orig/PKG-INFO 2019-08-13 04:18:18.000000000 +0200
+++ voluptuous-0.11.7/PKG-INFO 2020-06-26 10:39:30.204198402 +0200
@@ -690,9 +690,9 @@ Description: # Voluptuous is a Python da
## Running tests.
- Voluptuous is using nosetests:
+ Voluptuous is using pytest:
- $ nosetests
+ $ pytest
## Why use Voluptuous over another validation library?
Index: voluptuous-0.11.7/README.md
===================================================================
--- voluptuous-0.11.7.orig/README.md 2019-08-13 04:10:58.000000000 +0200
+++ voluptuous-0.11.7/README.md 2020-06-26 10:39:43.096273515 +0200
@@ -681,9 +681,9 @@ s({'password':'123', 'password_again': 1
## Running tests.
-Voluptuous is using nosetests:
+Voluptuous is using pytest:
- $ nosetests
+ $ pytest
## Why use Voluptuous over another validation library?
Index: voluptuous-0.11.7/pytest.ini
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ voluptuous-0.11.7/pytest.ini 2020-06-26 10:38:33.715869273 +0200
@@ -0,0 +1,4 @@
+[pytest]
+python_files = tests.py
+testpaths = voluptuous/tests
+addopts = --doctest-glob=*.md -v
Index: voluptuous-0.11.7/setup.cfg
===================================================================
--- voluptuous-0.11.7.orig/setup.cfg 2019-08-13 04:18:18.000000000 +0200
+++ voluptuous-0.11.7/setup.cfg 2020-06-26 10:47:34.899022422 +0200
@@ -1,8 +1,3 @@
-[nosetests]
-doctest-extension = md
-with-doctest = 1
-where = .
-
[egg_info]
tag_build =
tag_date = 0

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jun 18 09:59:14 UTC 2020 - pgajdos@suse.com
- added patches
https://github.com/alecthomas/voluptuous/pull/422
+ python-voluptuous-remove-nose.patch
------------------------------------------------------------------- -------------------------------------------------------------------
Mon Aug 26 11:41:09 UTC 2019 - Antonio Larrosa <alarrosa@suse.com> Mon Aug 26 11:41:09 UTC 2019 - Antonio Larrosa <alarrosa@suse.com>

View File

@ -1,7 +1,7 @@
# #
# spec file for package python-voluptuous # spec file for package python-voluptuous
# #
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # Copyright (c) 2020 SUSE LLC
# #
# All modifications and additions to the file contributed by third parties # All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed # remain the property of their copyright owners, unless otherwise agreed
@ -25,7 +25,9 @@ License: BSD-3-Clause
Group: Development/Languages/Python Group: Development/Languages/Python
URL: http://github.com/alecthomas/voluptuous URL: http://github.com/alecthomas/voluptuous
Source: https://files.pythonhosted.org/packages/source/v/voluptuous/voluptuous-%{version}.tar.gz Source: https://files.pythonhosted.org/packages/source/v/voluptuous/voluptuous-%{version}.tar.gz
BuildRequires: %{python_module nose} # https://github.com/alecthomas/voluptuous/pull/422
Patch0: python-voluptuous-remove-nose.patch
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module setuptools} BuildRequires: %{python_module setuptools}
BuildRequires: fdupes BuildRequires: fdupes
BuildRequires: python-rpm-macros BuildRequires: python-rpm-macros
@ -38,6 +40,7 @@ coming into Python as JSON, YAML, etc.
%prep %prep
%setup -q -n voluptuous-%{version} %setup -q -n voluptuous-%{version}
%patch0 -p1
%build %build
%python_build %python_build
@ -47,7 +50,7 @@ coming into Python as JSON, YAML, etc.
%python_expand %fdupes %{buildroot}%{$python_sitelib} %python_expand %fdupes %{buildroot}%{$python_sitelib}
%check %check
%python_exec %{_bindir}/nosetests -v %pytest
%files %{python_files} %files %{python_files}
%license COPYING %license COPYING