3
3
import collections
4
4
import logging
5
5
import optparse
6
+ from pathlib import Path
6
7
7
8
import pytest
8
9
import pretend
@@ -36,7 +37,7 @@ def parse_args(self):
36
37
return FakeOptParse
37
38
38
39
39
- def test_find_missing_reqs (monkeypatch ):
40
+ def test_find_missing_reqs (monkeypatch , tmp_path : Path ):
40
41
imported_modules = dict (spam = common .FoundModule ('spam' ,
41
42
'site-spam/spam.py' ,
42
43
[('ham.py' , 1 )]),
@@ -63,18 +64,15 @@ def test_find_missing_reqs(monkeypatch):
63
64
monkeypatch .setattr (find_missing_reqs , 'search_packages_info' ,
64
65
pretend .call_recorder (lambda x : packages_info ))
65
66
66
- fake_requirements_file_contents = dedent (
67
- """\
68
- spam
69
- """
70
- )
71
- FakeReq = collections .namedtuple ('FakeReq' , [])
72
- requirements = [FakeReq ()]
73
- monkeypatch .setattr (
74
- find_missing_reqs , 'parse_requirements' ,
75
- pretend .call_recorder (lambda a , session = None : requirements ))
67
+ fake_requirements_file = tmp_path / 'requirements.txt'
68
+ fake_requirements_file .write_text ('spam' )
76
69
77
- result = list (find_missing_reqs .find_missing_reqs (None ))
70
+ result = list (
71
+ find_missing_reqs .find_missing_reqs (
72
+ options = None ,
73
+ requirements_filename = str (fake_requirements_file ),
74
+ )
75
+ )
78
76
assert result == [('shrub' , [imported_modules ['shrub' ]])]
79
77
80
78
@@ -83,10 +81,25 @@ def test_main_failure(monkeypatch, caplog, fake_opts):
83
81
84
82
caplog .set_level (logging .WARN )
85
83
84
+ def fake_find_missing_reqs (options , requirements_filename ):
85
+ return [
86
+ (
87
+ 'missing' ,
88
+ [
89
+ common .FoundModule (
90
+ 'missing' ,
91
+ 'missing.py' ,
92
+ [('location.py' , 1 )],
93
+ )
94
+ ]
95
+ )
96
+ ]
97
+
86
98
monkeypatch .setattr (
87
- find_missing_reqs , 'find_missing_reqs' , lambda x : [('missing' , [
88
- common .FoundModule ('missing' , 'missing.py' , [('location.py' , 1 )])
89
- ])])
99
+ find_missing_reqs ,
100
+ 'find_missing_reqs' ,
101
+ fake_find_missing_reqs ,
102
+ )
90
103
91
104
with pytest .raises (SystemExit ) as excinfo :
92
105
find_missing_reqs .main ()
@@ -144,7 +157,11 @@ def parse_args(self):
144
157
145
158
monkeypatch .setattr (optparse , 'OptionParser' , FakeOptParse )
146
159
147
- monkeypatch .setattr (find_missing_reqs , 'find_missing_reqs' , lambda x : [])
160
+ monkeypatch .setattr (
161
+ find_missing_reqs ,
162
+ 'find_missing_reqs' ,
163
+ lambda options , requirements_filename : [],
164
+ )
148
165
find_missing_reqs .main ()
149
166
150
167
for event in [(logging .DEBUG , 'debug' ), (logging .INFO , 'info' ),
0 commit comments