Skip to content
Myr

Fixed lack of clear reporting for paths

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent a2c58d5 · Browse files · 2 files+7 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−7 removed

  • tests:+2 added−2 removed
  • other:+5 added−5 removed

2 files+7 added−7 removed

modified:click/types.py+5 added-5 removed
343 unmodified lines
344 return rv345 self.fail('%s "%s" does not exist.' % (346 self.path_type,347 filename_to_ui(value)348 ))348 ), param, ctx)349350 if not self.file_okay and stat.S_ISREG(st.st_mode):351 self.fail('%s "%s" is a file.' % (352 self.path_type,353 filename_to_ui(value)354 ))354 ), param, ctx)355 if not self.dir_okay and stat.S_ISDIR(st.st_mode):356 self.fail('%s "%s" is a directory.' % (357 self.path_type,358 filename_to_ui(value)359 ))359 ), param, ctx)360 if self.writable and not os.access(value, os.W_OK):361 self.fail('%s "%s" is not writable.' % (362 self.path_type,363 filename_to_ui(value)364 ))364 ), param, ctx)365 if self.readable and not os.access(value, os.R_OK):366 self.fail('%s "%s" is not readable.' % (367 self.path_type,368 filename_to_ui(value)369 ))369 ), param, ctx)370371 return rv372373
45 unmodified lines
modified:tests/test_basic.py+2 added-2 removed
247 unmodified lines
248 with open('test/foo.txt', 'rb') as f:249 assert f.read() == b'meh\n'250251 result = runner.invoke(write_to_dir, ['-O', 'test/foo.txt'])252 assert 'Invalid value: Directory "test/foo.txt" is a file.' \252 assert 'Invalid value for "-O": Directory "test/foo.txt" is a file.' \253 in result.output254255 @click.command()256 @click.option('-f', type=click.Path(exists=True))
2 unmodified lines
259 click.echo('is_dir=%s' % os.path.isdir(f))260261 with runner.isolated_filesystem():262 result = runner.invoke(showtype, ['-f', 'xxx'])263 assert 'Error: Invalid value: Path "xxx" does not exist' \263 assert 'Error: Invalid value for "-f": Path "xxx" does not exist' \264 in result.output265266 result = runner.invoke(showtype, ['-f', '.'])267 assert 'is_file=False' in result.output
121 unmodified lines