Skip to content

Commit ded2879

Browse files
committed
Refactor license option tests to use Mock objects instead of lambdas
Using Mock objects makes the intent more clearer compared to how we were using lambdas.
1 parent 549743a commit ded2879

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

tests/_models/test_package.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,57 +107,57 @@ def test_dist_package_as_dict() -> None:
107107
("mocked_metadata", "expected_output"),
108108
[
109109
pytest.param(
110-
Mock(
111-
get=lambda *args, **kwargs: None, # noqa: ARG005
112-
get_all=lambda *args, **kwargs: [], # noqa: ARG005
113-
),
110+
Mock(get=Mock(return_value=None), get_all=Mock(return_value=[])),
114111
Package.UNKNOWN_LICENSE_STR,
115112
id="no-license",
116113
),
117114
pytest.param(
118115
Mock(
119-
get=lambda *args, **kwargs: None, # noqa: ARG005
120-
get_all=lambda *args, **kwargs: [ # noqa: ARG005
121-
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
122-
"Operating System :: OS Independent",
123-
],
116+
get=Mock(return_value=None),
117+
get_all=Mock(
118+
return_value=[
119+
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
120+
"Operating System :: OS Independent",
121+
]
122+
),
124123
),
125124
"(GNU General Public License v2 (GPLv2))",
126125
id="one-license-with-one-non-license",
127126
),
128127
pytest.param(
129128
Mock(
130-
get=lambda *args, **kwargs: None, # noqa: ARG005
131-
get_all=lambda *args, **kwargs: [ # noqa: ARG005
132-
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
133-
"License :: OSI Approved :: Apache Software License",
134-
],
129+
get=Mock(return_value=None),
130+
get_all=Mock(
131+
return_value=[
132+
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
133+
"License :: OSI Approved :: Apache Software License",
134+
]
135+
),
135136
),
136137
"(GNU General Public License v2 (GPLv2), Apache Software License)",
137138
id="more-than-one-license",
138139
),
139140
pytest.param(
140-
Mock(
141-
get=lambda *args, **kwargs: "MIT", # noqa: ARG005
142-
get_all=lambda *args, **kwargs: [], # noqa: ARG005
143-
),
141+
Mock(get=Mock(return_value="MIT"), get_all=Mock(return_value=[])),
144142
"(MIT)",
145143
id="license-expression",
146144
),
147145
pytest.param(
148146
Mock(
149-
get=lambda *args, **kwargs: "MIT", # noqa: ARG005
150-
get_all=lambda *args, **kwargs: [ # noqa: ARG005
151-
"License :: OSI Approved :: MIT License",
152-
],
147+
get=Mock(return_value="MIT"),
148+
get_all=Mock(
149+
return_value=[
150+
"License :: OSI Approved :: MIT License",
151+
]
152+
),
153153
),
154154
"(MIT)",
155155
id="license-expression-with-license-classifier",
156156
),
157157
],
158158
)
159159
def test_dist_package_licenses(mocked_metadata: Mock, expected_output: str, monkeypatch: pytest.MonkeyPatch) -> None:
160-
monkeypatch.setattr("pipdeptree._models.package.metadata", lambda _: mocked_metadata)
160+
monkeypatch.setattr("pipdeptree._models.package.metadata", Mock(return_value=mocked_metadata))
161161
dist = DistPackage(Mock(metadata={"Name": "a"}))
162162
licenses_str = dist.licenses()
163163

0 commit comments

Comments
 (0)