Skip to content

Commit c156440

Browse files
Berthin TorresBerthin Torres
authored andcommitted
fix tests
1 parent 2d60212 commit c156440

2 files changed

Lines changed: 26 additions & 27 deletions

File tree

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ math
119119
netrc
120120
-----
121121

122-
* Added support for the :envvar:`NETRC` environment variable in :func:`netrc.netrc`.
122+
* Added support for the :envvar:`!NETRC` environment variable in :func:`netrc.netrc`.
123123
(Contributed by Berthin Torres in :gh:`135788`.)
124124

125125

Lib/test/test_netrc.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import netrc, os, unittest, sys, textwrap
1+
import netrc, os, unittest, sys, tempfile, textwrap
22
from contextlib import ExitStack
3-
from test import support
4-
from test.support import os_helper
3+
from test.support import os_helper, subTests
54

65
try:
76
import pwd
@@ -24,7 +23,7 @@ def __enter__(self):
2423
self.environ = self.stack.enter_context(
2524
os_helper.EnvironmentVarGuard(),
2625
)
27-
self.tmpdir = self.stack.enter_context(os_helper.temp_dir())
26+
self.tmpdir = self.stack.enter_context(tempfile.TemporaryDirectory())
2827
return self
2928

3029
def __exit__(self, *ignore_exc):
@@ -89,7 +88,7 @@ def use_file_argument(*args, **kwargs):
8988
def get_all_scenarios():
9089
"""Return all `.netrc` loading scenarios as callables.
9190
92-
This method is useful for iterating through all supported ways the
91+
This method is useful for iterating through all d ways the
9392
`.netrc` file can be located.
9493
"""
9594
return (NetrcBuilder.use_default_netrc_in_home,
@@ -100,7 +99,7 @@ def get_all_scenarios():
10099
class NetrcTestCase(unittest.TestCase):
101100
ALL_NETRC_FILE_SCENARIOS = NetrcBuilder.get_all_scenarios()
102101

103-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
102+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
104103
def test_toplevel_non_ordered_tokens(self, make_nrc):
105104
nrc = make_nrc("""\
106105
machine host.domain.com password pass1 login log1 account acct1
@@ -110,7 +109,7 @@ def test_toplevel_non_ordered_tokens(self, make_nrc):
110109
('log1', 'acct1', 'pass1'))
111110
self.assertEqual(nrc.hosts['default'], ('log2', 'acct2', 'pass2'))
112111

113-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
112+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
114113
def test_toplevel_tokens(self, make_nrc):
115114
nrc = make_nrc("""\
116115
machine host.domain.com login log1 password pass1 account acct1
@@ -120,7 +119,7 @@ def test_toplevel_tokens(self, make_nrc):
120119
('log1', 'acct1', 'pass1'))
121120
self.assertEqual(nrc.hosts['default'], ('log2', 'acct2', 'pass2'))
122121

123-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
122+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
124123
def test_macros(self, make_nrc):
125124
data = """\
126125
macdef macro1
@@ -139,7 +138,7 @@ def test_macros(self, make_nrc):
139138
self.assertRaises(netrc.NetrcParseError, make_nrc,
140139
data.rstrip(' ')[:-1])
141140

142-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
141+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
143142
def test_optional_tokens(self, make_nrc):
144143
data = (
145144
"machine host.domain.com",
@@ -166,7 +165,7 @@ def test_optional_tokens(self, make_nrc):
166165
nrc = make_nrc(item)
167166
self.assertEqual(nrc.hosts['default'], ('', '', ''))
168167

169-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
168+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
170169
def test_invalid_tokens(self, make_nrc):
171170
data = (
172171
"invalid host.domain.com",
@@ -187,7 +186,7 @@ def _test_token_x(self, make_nrc, content, token, value):
187186
elif token == 'password':
188187
self.assertEqual(nrc.hosts['host.domain.com'], ('log', 'acct', value))
189188

190-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
189+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
191190
def test_token_value_quotes(self, make_nrc):
192191
self._test_token_x(make_nrc, """\
193192
machine host.domain.com login "log" password pass account acct
@@ -199,7 +198,7 @@ def test_token_value_quotes(self, make_nrc):
199198
machine host.domain.com login log password "pass" account acct
200199
""", 'password', 'pass')
201200

202-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
201+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
203202
def test_token_value_escape(self, make_nrc):
204203
self._test_token_x(make_nrc, """\
205204
machine host.domain.com login \\"log password pass account acct
@@ -220,7 +219,7 @@ def test_token_value_escape(self, make_nrc):
220219
machine host.domain.com login log password "\\"pass" account acct
221220
""", 'password', '"pass')
222221

223-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
222+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
224223
def test_token_value_whitespace(self, make_nrc):
225224
self._test_token_x(make_nrc, """\
226225
machine host.domain.com login "lo g" password pass account acct
@@ -232,7 +231,7 @@ def test_token_value_whitespace(self, make_nrc):
232231
machine host.domain.com login log password pass account "acc t"
233232
""", 'account', 'acc t')
234233

235-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
234+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
236235
def test_token_value_non_ascii(self, make_nrc):
237236
self._test_token_x(make_nrc, """\
238237
machine host.domain.com login \xa1\xa2 password pass account acct
@@ -244,7 +243,7 @@ def test_token_value_non_ascii(self, make_nrc):
244243
machine host.domain.com login log password \xa1\xa2 account acct
245244
""", 'password', '\xa1\xa2')
246245

247-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
246+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
248247
def test_token_value_leading_hash(self, make_nrc):
249248
self._test_token_x(make_nrc, """\
250249
machine host.domain.com login #log password pass account acct
@@ -256,7 +255,7 @@ def test_token_value_leading_hash(self, make_nrc):
256255
machine host.domain.com login log password #pass account acct
257256
""", 'password', '#pass')
258257

259-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
258+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
260259
def test_token_value_trailing_hash(self, make_nrc):
261260
self._test_token_x(make_nrc, """\
262261
machine host.domain.com login log# password pass account acct
@@ -268,7 +267,7 @@ def test_token_value_trailing_hash(self, make_nrc):
268267
machine host.domain.com login log password pass# account acct
269268
""", 'password', 'pass#')
270269

271-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
270+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
272271
def test_token_value_internal_hash(self, make_nrc):
273272
self._test_token_x(make_nrc, """\
274273
machine host.domain.com login lo#g password pass account acct
@@ -285,31 +284,31 @@ def _test_comment(self, make_nrc, content, passwd='pass'):
285284
self.assertEqual(nrc.hosts['foo.domain.com'], ('bar', '', passwd))
286285
self.assertEqual(nrc.hosts['bar.domain.com'], ('foo', '', 'pass'))
287286

288-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
287+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
289288
def test_comment_before_machine_line(self, make_nrc):
290289
self._test_comment(make_nrc, """\
291290
# comment
292291
machine foo.domain.com login bar password pass
293292
machine bar.domain.com login foo password pass
294293
""")
295294

296-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
295+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
297296
def test_comment_before_machine_line_no_space(self, make_nrc):
298297
self._test_comment(make_nrc, """\
299298
#comment
300299
machine foo.domain.com login bar password pass
301300
machine bar.domain.com login foo password pass
302301
""")
303302

304-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
303+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
305304
def test_comment_before_machine_line_hash_only(self, make_nrc):
306305
self._test_comment(make_nrc, """\
307306
#
308307
machine foo.domain.com login bar password pass
309308
machine bar.domain.com login foo password pass
310309
""")
311310

312-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
311+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
313312
def test_comment_after_machine_line(self, make_nrc):
314313
self._test_comment(make_nrc, """\
315314
machine foo.domain.com login bar password pass
@@ -322,7 +321,7 @@ def test_comment_after_machine_line(self, make_nrc):
322321
# comment
323322
""")
324323

325-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
324+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
326325
def test_comment_after_machine_line_no_space(self, make_nrc):
327326
self._test_comment(make_nrc, """\
328327
machine foo.domain.com login bar password pass
@@ -335,7 +334,7 @@ def test_comment_after_machine_line_no_space(self, make_nrc):
335334
#comment
336335
""")
337336

338-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
337+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
339338
def test_comment_after_machine_line_hash_only(self, make_nrc):
340339
self._test_comment(make_nrc, """\
341340
machine foo.domain.com login bar password pass
@@ -348,21 +347,21 @@ def test_comment_after_machine_line_hash_only(self, make_nrc):
348347
#
349348
""")
350349

351-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
350+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
352351
def test_comment_at_end_of_machine_line(self, make_nrc):
353352
self._test_comment(make_nrc, """\
354353
machine foo.domain.com login bar password pass # comment
355354
machine bar.domain.com login foo password pass
356355
""")
357356

358-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
357+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
359358
def test_comment_at_end_of_machine_line_no_space(self, make_nrc):
360359
self._test_comment(make_nrc, """\
361360
machine foo.domain.com login bar password pass #comment
362361
machine bar.domain.com login foo password pass
363362
""")
364363

365-
@support.subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
364+
@subTests('make_nrc', ALL_NETRC_FILE_SCENARIOS)
366365
def test_comment_at_end_of_machine_line_pass_has_hash(self, make_nrc):
367366
self._test_comment(make_nrc, """\
368367
machine foo.domain.com login bar password #pass #comment

0 commit comments

Comments
 (0)