Beispiel #1
0
def bga_url_tester(url: Url, model_path: str, debug: bool, interactive: bool,
                   domain: Url):
    domain = domain or get_domain(url)
    model_class: t.Type[PageFragment] = import_dotted_path(model_path)
    loop = asyncio.get_event_loop()
    response = loop.run_until_complete(async_main(url))
    model: PageFragment = model_class(response.text,
                                      metadata=PageMetadata(
                                          url=url,
                                          domain=domain,
                                          source_html=response.text))
    serialized: str = pprint.pformat(model.to_dict())
    rprint("[yellow]Result:", serialized)
    interactive_stop(interactive, "after response", locals())
def test_import_attribute_error():
    with pytest.raises(ImportError) as error_info:
        import_dotted_path('imports.test_import_dotted_path:Bar')
    assert error_info.value.msg == (
        "Module 'imports.test_import_dotted_path' does not define a 'Bar' "
        "attribute/class")
def test_import_module_error():
    with pytest.raises(ImportError) as error_info:
        import_dotted_path('not_existing_module')
    assert error_info.value.msg == "'not_existing_module' doesn't look like a module path"
def test_import_colon_inner_method():
    result = import_dotted_path('imports.test_import_dotted_path:Foo.Bar.baz')
    assert result is Foo.Bar.baz
    assert result(Foo.Bar()) == 42
def test_import_colon_inner_class():
    result = import_dotted_path('imports.test_import_dotted_path:Foo.Bar')
    assert result is Foo.Bar
def test_import_dotted_function():
    result = import_dotted_path(
        'imports.test_import_dotted_path.importable_function')
    assert result is importable_function
def test_import_dotted_class():
    result = import_dotted_path('imports.test_import_dotted_path.Foo')
    assert result is Foo
Beispiel #8
0
def test_import_colon_class():
    result = import_dotted_path("imports.test_import_dotted_path:Foo")
    assert result is Foo