Skip to content

Commit 9a5cb1f

Browse files
authored
Merge pull request #280 from novafloss/fix-tests-on-mutable-objects
#279 Fix tests on the mutable objects.
2 parents 4abc2a8 + 4127668 commit 9a5cb1f

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

demo/tests/test_validators.py

+18-35
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ def setUp(self):
1515
)
1616
self.validation_object = ValidatorFactory()
1717

18-
def test_min_length(self):
19-
mock_object = mock.Mock()
20-
ValidatorFactory.min_length = mock_object
18+
@mock.patch('formidable.validators.ValidatorFactory.min_length')
19+
def test_min_length(self, mock_object):
2120
self.validation_object.produce(
2221
self.validation_named_tuple(
2322
type='MINLENGTH',
@@ -28,10 +27,8 @@ def test_min_length(self):
2827

2928
assert mock_object.called
3029

31-
def test_max_length(self):
32-
mock_object = mock.Mock()
33-
ValidatorFactory.max_length = mock_object
34-
30+
@mock.patch('formidable.validators.ValidatorFactory.max_length')
31+
def test_max_length(self, mock_object):
3532
self.validation_object.produce(
3633
self.validation_named_tuple(
3734
type='MAXLENGTH',
@@ -42,10 +39,8 @@ def test_max_length(self):
4239

4340
assert mock_object.called
4441

45-
def test_regexp(self):
46-
mock_object = mock.Mock()
47-
ValidatorFactory.regexp = mock_object
48-
42+
@mock.patch('formidable.validators.ValidatorFactory.regexp')
43+
def test_regexp(self, mock_object):
4944
self.validation_object.produce(
5045
self.validation_named_tuple(
5146
type='REGEXP',
@@ -56,10 +51,8 @@ def test_regexp(self):
5651

5752
assert mock_object.called
5853

59-
def test_gt(self):
60-
mock_object = mock.Mock()
61-
ValidatorFactory.gt = mock_object
62-
54+
@mock.patch('formidable.validators.ValidatorFactory.gt')
55+
def test_gt(self, mock_object):
6356
self.validation_object.produce(
6457
self.validation_named_tuple(
6558
type='GT',
@@ -70,10 +63,8 @@ def test_gt(self):
7063

7164
assert mock_object.called
7265

73-
def test_gte(self):
74-
mock_object = mock.Mock()
75-
ValidatorFactory.gte = mock_object
76-
66+
@mock.patch('formidable.validators.ValidatorFactory.gte')
67+
def test_gte(self, mock_object):
7768
self.validation_object.produce(
7869
self.validation_named_tuple(
7970
type='GTE',
@@ -84,10 +75,8 @@ def test_gte(self):
8475

8576
assert mock_object.called
8677

87-
def test_lt(self):
88-
mock_object = mock.Mock()
89-
ValidatorFactory.lt = mock_object
90-
78+
@mock.patch('formidable.validators.ValidatorFactory.lt')
79+
def test_lt(self, mock_object):
9180
self.validation_object.produce(
9281
self.validation_named_tuple(
9382
type='LT',
@@ -98,10 +87,8 @@ def test_lt(self):
9887

9988
assert mock_object.called
10089

101-
def test_lte(self):
102-
mock_object = mock.Mock()
103-
ValidatorFactory.lte = mock_object
104-
90+
@mock.patch('formidable.validators.ValidatorFactory.lte')
91+
def test_lte(self, mock_object):
10592
self.validation_object.produce(
10693
self.validation_named_tuple(
10794
type='LTE',
@@ -112,10 +99,8 @@ def test_lte(self):
11299

113100
assert mock_object.called
114101

115-
def test_eq(self):
116-
mock_object = mock.Mock()
117-
ValidatorFactory.eq = mock_object
118-
102+
@mock.patch('formidable.validators.ValidatorFactory.eq')
103+
def test_eq(self, mock_object):
119104
self.validation_object.produce(
120105
self.validation_named_tuple(
121106
type='EQ',
@@ -126,10 +111,8 @@ def test_eq(self):
126111

127112
assert mock_object.called
128113

129-
def test_neq(self):
130-
mock_object = mock.Mock()
131-
ValidatorFactory.neq = mock_object
132-
114+
@mock.patch('formidable.validators.ValidatorFactory.neq')
115+
def test_neq(self, mock_object):
133116
self.validation_object.produce(
134117
self.validation_named_tuple(
135118
type='NEQ',

0 commit comments

Comments
 (0)