Skip to content

Commit 7313568

Browse files
committed
some test fixes and also self-check fix
1 parent 3f1a768 commit 7313568

File tree

3 files changed

+51
-41
lines changed

3 files changed

+51
-41
lines changed

pip_missing_reqs/find_missing_reqs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,15 @@ def main():
248248
options.ignore_files = ignorer(options.ignore_files)
249249
options.ignore_mods = ignorer(options.ignore_mods)
250250

251-
options.paths = args or ['.']
251+
options.paths = args
252252

253253
logging.basicConfig(format='%(message)s')
254254
log.setLevel(logging.INFO if options.verbose else logging.WARN)
255255

256256
missing = find_missing_reqs(options)
257+
258+
if missing:
259+
log.warning('Missing requirements:')
257260
for name, uses in missing:
258261
for use in uses:
259262
for filename, lineno in use.locations:

pip_missing_reqs/test_find_missing_reqs.py

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@
1414
from . import find_missing_reqs
1515

1616

17+
@pytest.fixture
18+
def fake_opts():
19+
20+
class FakeOptParse:
21+
class options:
22+
paths = ['dummy']
23+
verbose = True
24+
version = False
25+
ignore_files = []
26+
ignore_mods = []
27+
options = options()
28+
args = ['ham.py']
29+
30+
def __init__(self, usage):
31+
pass
32+
33+
def add_option(*args, **kw):
34+
pass
35+
36+
def parse_args(self):
37+
return (self.options, self.args)
38+
39+
return FakeOptParse
40+
41+
1742
@pytest.mark.parametrize(["path", "result"], [
1843
('/', ''),
1944
('__init__.py', ''), # a top-level file like this has no package name
@@ -182,25 +207,8 @@ def test_find_missing_reqs(monkeypatch):
182207
assert result == [('shrub', [imported_modules['shrub']])]
183208

184209

185-
def test_main_failure(monkeypatch, caplog):
186-
class options:
187-
paths = ['dummy']
188-
verbose = True
189-
ignore_files = []
190-
ignore_mods = []
191-
options = options()
192-
193-
class FakeOptParse:
194-
def __init__(self, usage):
195-
pass
196-
197-
def add_option(*args, **kw):
198-
pass
199-
200-
def parse_args(self):
201-
return (options, ['ham.py'])
202-
203-
monkeypatch.setattr(optparse, 'OptionParser', FakeOptParse)
210+
def test_main_failure(monkeypatch, caplog, fake_opts):
211+
monkeypatch.setattr(optparse, 'OptionParser', fake_opts)
204212

205213
caplog.setLevel(logging.WARN)
206214

@@ -214,32 +222,22 @@ def parse_args(self):
214222
assert excinfo.value == 1
215223

216224
assert caplog.records()[0].message == \
225+
'Missing requirements:'
226+
assert caplog.records()[1].message == \
217227
'location.py:1 dist=missing module=missing'
218228

219229

220-
def test_main_no_spec(monkeypatch, caplog):
221-
class FakeOptParse:
222-
def __init__(self, usage):
223-
pass
224-
225-
def add_option(*args, **kw):
226-
pass
227-
228-
def parse_args(self):
229-
return (None, [])
230-
231-
error = pretend.call_recorder(lambda *a: None)
232-
233-
monkeypatch.setattr(optparse, 'OptionParser', FakeOptParse)
234-
monkeypatch.setattr(find_missing_reqs, 'ignorer',
235-
pretend.call_recorder(lambda a: None))
230+
def test_main_no_spec(monkeypatch, caplog, fake_opts):
231+
fake_opts.args = []
232+
monkeypatch.setattr(optparse, 'OptionParser', fake_opts)
233+
monkeypatch.setattr(fake_opts, 'error',
234+
pretend.call_recorder(lambda s, e: None), raising=False)
236235

237236
with pytest.raises(SystemExit) as excinfo:
238237
find_missing_reqs.main()
239238
assert excinfo.value == 2
240239

241-
assert FakeOptParse.error.calls
242-
assert not find_missing_reqs.ignorer.calls
240+
assert fake_opts.error.calls
243241

244242

245243
@pytest.mark.parametrize(["ignore_cfg", "candidate", "result"], [
@@ -267,6 +265,7 @@ def test_logging_config(monkeypatch, caplog, verbose_cfg, events, result):
267265
class options:
268266
paths = ['dummy']
269267
verbose = verbose_cfg
268+
version = False
270269
ignore_files = []
271270
ignore_mods = []
272271
options = options()
@@ -291,3 +290,12 @@ def parse_args(self):
291290

292291
messages = [r.message for r in caplog.records()]
293292
assert messages == result
293+
294+
295+
def test_main_version(monkeypatch, caplog, fake_opts):
296+
fake_opts.options.version = True
297+
monkeypatch.setattr(optparse, 'OptionParser', fake_opts)
298+
299+
with pytest.raises(SystemExit) as excinfo:
300+
find_missing_reqs.main()
301+
assert excinfo.value == 'version'

tox.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ deps = flake8
2424
commands = flake8 pip_missing_reqs
2525

2626
[testenv:pip-missing-reqs]
27-
deps = pip_missing_reqs
28-
commands = pip-missing-reqs --ignore-file=pip_missing_reqs/test* \
29-
pip_missing_reqs
27+
commands = python -m pip_missing_reqs.find_missing_reqs \
28+
--ignore-file=pip_missing_reqs/test* pip_missing_reqs
3029

0 commit comments

Comments
 (0)