declarative-mocks 0.4.1__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: declarative-mocks
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Declare mock behavior as ordered expectations. Simple, typed, gomock-inspired DSL over unittest.mock
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -69,17 +69,19 @@ service = Mock(spec=Directory)
69
69
  service.lookup.return_value = User(id=1, name="Ada", email="ada@example.com")
70
70
 
71
71
  user = service.lookup("ada")
72
- assert isinstance(user.id, int)
73
- assert user.name.startswith("A")
74
- assert "@" in user.email
72
+ assert user.id == 1
73
+ assert user.name == "Ada"
74
+ assert user.email == "ada@example.com"
75
75
  assert abs((datetime.now() - user.created_at).total_seconds()) < 5
76
- service.lookup.assert_called_once_with("ada")
76
+ name = service.lookup.call_args.args[0]
77
+ assert isinstance(name, str)
78
+ assert name.startswith("a")
77
79
  ```
78
80
 
79
81
  Here's an example of how **dmock** improves your tests:
80
82
 
81
83
  ```python
82
- from dmock import AnythingOfType, Contains, DeclarativeMock, IsNow, StartsWith
84
+ from dmock import DeclarativeMock, IsNow, StartsWith
83
85
 
84
86
  service = DeclarativeMock(Directory)
85
87
  service.expect(Directory.lookup, StartsWith("a")).returns(
@@ -147,7 +149,7 @@ calc = DeclarativeMock(Calculator)
147
149
  calc.expect("price", 100).returns(99).once()
148
150
  assert calc.price(100) == 99
149
151
 
150
- calc.expect("price", 200).returns(99).times(3) # last outcome repeats for the extra calls
152
+ calc.expect("price", 200).returns(99, repeat=2).times(3) # last outcome repeats for the extra calls
151
153
  assert [calc.price(200) for _ in range(3)] == [99, 99, 99]
152
154
 
153
155
  calc.expect("price", 300).returns(99).between(1, 3)
@@ -40,17 +40,19 @@ service = Mock(spec=Directory)
40
40
  service.lookup.return_value = User(id=1, name="Ada", email="ada@example.com")
41
41
 
42
42
  user = service.lookup("ada")
43
- assert isinstance(user.id, int)
44
- assert user.name.startswith("A")
45
- assert "@" in user.email
43
+ assert user.id == 1
44
+ assert user.name == "Ada"
45
+ assert user.email == "ada@example.com"
46
46
  assert abs((datetime.now() - user.created_at).total_seconds()) < 5
47
- service.lookup.assert_called_once_with("ada")
47
+ name = service.lookup.call_args.args[0]
48
+ assert isinstance(name, str)
49
+ assert name.startswith("a")
48
50
  ```
49
51
 
50
52
  Here's an example of how **dmock** improves your tests:
51
53
 
52
54
  ```python
53
- from dmock import AnythingOfType, Contains, DeclarativeMock, IsNow, StartsWith
55
+ from dmock import DeclarativeMock, IsNow, StartsWith
54
56
 
55
57
  service = DeclarativeMock(Directory)
56
58
  service.expect(Directory.lookup, StartsWith("a")).returns(
@@ -118,7 +120,7 @@ calc = DeclarativeMock(Calculator)
118
120
  calc.expect("price", 100).returns(99).once()
119
121
  assert calc.price(100) == 99
120
122
 
121
- calc.expect("price", 200).returns(99).times(3) # last outcome repeats for the extra calls
123
+ calc.expect("price", 200).returns(99, repeat=2).times(3) # last outcome repeats for the extra calls
122
124
  assert [calc.price(200) for _ in range(3)] == [99, 99, 99]
123
125
 
124
126
  calc.expect("price", 300).returns(99).between(1, 3)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "declarative-mocks"
3
- version = "0.4.1"
3
+ version = "0.4.2"
4
4
  description = "Declare mock behavior as ordered expectations. Simple, typed, gomock-inspired DSL over unittest.mock"
5
5
  authors = [{ name = "Dimitry Churilov", email = "d.mdx3r@gmail.com" }]
6
6
  license = "MIT"