def test_exceptions3():
    with tempfile.TemporaryDirectory() as tmp_dir:
        with pytest.raises(KnownError, match='Errno 13'):
            load_page('/', 'http://google.com')
        with pytest.raises(KnownError, match='Errno 17'):
            os.mkdir(f'{tmp_dir}/google-com_files')
            load_page(tmp_dir, 'http://google.com/')
Beispiel #2
0
def test_load_file():
    url = 'https://hexlet.io/courses'
    with tempfile.TemporaryDirectory() as temp_dir:
        engine.load_page(temp_dir, url)
        name_file = engine.get_name(url)
        temp_path_file = os.path.join(temp_dir, name_file)
        assert os.path.exists(temp_path_file) == True
Beispiel #3
0
def main():
    """Parse arguments from CLI and load page."""
    args = engine.parser.parse_args()
    engine.load_page(
        args.output,
        args.url,
    )
def main():
    logger = logging.getLogger()
    args = arg_parse()
    logger.setLevel(args.log.upper())
    logger.info('downloading started')
    try:
        load_page(args.output, args.url)
    except KnownError:
        sys.exit(1)
    else:
        logger.info('downloading finished')
        sys.exit(0)
def test_load_page():
    with tempfile.TemporaryDirectory() as tmp_dir:
        load_page(tmp_dir, URL2)
        assert os.path.exists(os.path.join(tmp_dir, PATH_URL1))
        assert os.path.exists(os.path.join(tmp_dir, PATH_FILES))
        assert os.path.exists(os.path.join(tmp_dir, PATH_FILES, PATH_FILE1))
        assert os.path.exists(os.path.join(tmp_dir, PATH_FILES, PATH_FILE2))
        assert os.path.exists(os.path.join(tmp_dir, PATH_FILES, PATH_FILE3))
        text = txt_load(os.path.join(tmp_dir, PATH_URL1))
        attr_list, _ = change_attrs(text, '_')
        assert attr_list == [
            os.path.join(PATH_FILES, PATH_FILE1),
            os.path.join(PATH_FILES, PATH_FILE2),
            os.path.join(PATH_FILES, PATH_FILE3)
        ]
Beispiel #6
0
def test_check_exception(url, dir, error):
    with tempfile.TemporaryDirectory() as temp_dir:
        with pytest.raises(SystemExit) as e:
            engine.load_page(dir, url)
        assert (error in str(e.value)) == True
def test_exceptions2():
    with tempfile.TemporaryDirectory() as tmp_dir:
        with pytest.raises(KnownError, match='401'):
            load_page(tmp_dir, 'https://httpstat.us/401')
        with pytest.raises(KnownError, match='404'):
            load_page(tmp_dir, 'https://httpstat.us/404')
def test_exceptions1():
    with tempfile.TemporaryDirectory() as tmp_dir:
        with pytest.raises(KnownError, match='Errno -2'):
            load_page(tmp_dir, 'https://nonexistent-page.bla')