def test_permissions_exception(): with TemporaryDirectory() as tmpdir: os.chmod(tmpdir, 400) with pytest.raises(PermissionError) as excinfo: url = 'https://hexlet.io/courses' download(tmpdir, url) assert 'Permission denied' in str(excinfo.value)
def test_has_local_resources(): with TemporaryDirectory() as tmpdir: download(tmpdir, 'https://clojure.org') expected = os.path.join( tmpdir, 'clojure-org_files', ) assert len(os.listdir(os.path.join(expected))) != 0
def main(): """Download and save specified webpage.""" args = make_parser().parse_args() configure_logger(args.log_level) try: download(args.output, args.url) except Exception as e: if 'url' in str(e.args): sys.exit(1) elif 'Permission denied' in str(e.args): sys.exit(2) sys.exit(0)
def test_404_exception(): with TemporaryDirectory() as tmpdir: with pytest.raises(HTTPError) as excinfo: url = 'https://grishaev.me/bookshelf2' download(tmpdir, url) assert '404 Client Error' in str(excinfo.value)
def test_download(): with TemporaryDirectory() as tmpdir: download(tmpdir, 'http://example.com') actual = read_file(os.path.join(tmpdir, 'example-com.html')) expected = read_file('./tests/fixtures/example-com.html') assert actual == expected