예제 #1
0
def test_fail_to_import_module_with_dot_path_syntax():
    """Import a module using the "dot" path syntax."""
    with pytest.raises(ImportError, match=r"possible causes"):
        get_object_tree("does_not_exist")
예제 #2
0
def test_fail_to_import_attribute_with_dot_path_syntax():
    """Import an attribute using the "dot" path syntax."""
    with pytest.raises(AttributeError) as error:
        leaf = get_object_tree(
            "tests.fixtures.the_package.the_module.does_not_exist")
예제 #3
0
def test_fail_to_import_module_with_colon_path_syntax():
    """Import a module using the "colon" path syntax."""
    with pytest.raises(ImportError):
        get_object_tree("tests.fixtures.does_not_exist", new_path_syntax=True)
예제 #4
0
def test_fail_to_import_nested_attribute_with_colon_path_syntax():
    """Import a nested attribute using the "colon" path syntax."""
    with pytest.raises(AttributeError) as error:
        leaf = get_object_tree(
            "tests.fixtures.the_package.the_module:TheClass.does_not_exist")
예제 #5
0
def test_import_module_with_colon_path_syntax():
    """Import a module using the "colon" path syntax."""
    leaf = get_object_tree("tests.fixtures.the_package.the_module",
                           new_path_syntax=True)
예제 #6
0
def test_import_nested_attribute_with_colon_path_syntax():
    """Import a nested attribute using the "colon" path syntax."""
    leaf = get_object_tree(
        "tests.fixtures.the_package.the_module:TheClass.THE_ATTRIBUTE")
예제 #7
0
def test_can_find_class_attribute_real_path():
    """Find real path of a class attribute."""
    leaf = get_object_tree(
        "tests.fixtures.real_path.module_a.DefinedInModuleB.ATTRIBUTE")
    assert leaf.dotted_path == "tests.fixtures.real_path.module_b.DefinedInModuleB.ATTRIBUTE"
예제 #8
0
def test_cannot_find_module_attribute_real_path():
    """Find real path of a module attribute."""
    leaf = get_object_tree("tests.fixtures.real_path.module_a.ATTRIBUTE")
    assert leaf.dotted_path != "tests.fixtures.real_path.module_b.ATTRIBUTE"
예제 #9
0
def test_import_error():
    """Raise error when getting tree for missing object."""
    with pytest.raises(ImportError):
        get_object_tree("eeeeeeeeeeeeeeeeeee")
예제 #10
0
def test_can_find_class_method_real_path():
    """Find real path of a class method."""
    leaf = get_object_tree(
        "tests.fixtures.real_path.module_a.DefinedInModuleB.method")
    assert leaf.dotted_path == "tests.fixtures.real_path.module_b.DefinedInModuleB.method"
예제 #11
0
def test_import_no_path():
    """Raise error when getting tree for empty object name."""
    with pytest.raises(ValueError):
        get_object_tree("")
예제 #12
0
def test_import_no_path():
    with pytest.raises(ValueError):
        get_object_tree("")
예제 #13
0
def test_cannot_find_module_attribute_real_path():
    leaf = get_object_tree("tests.fixtures.real_path.module_a.ATTRIBUTE")
    assert not leaf.dotted_path == "tests.fixtures.real_path.module_b.ATTRIBUTE"
예제 #14
0
def test_can_find_class_real_path():
    leaf = get_object_tree(
        "tests.fixtures.real_path.module_a.DefinedInModuleB")
    assert leaf.dotted_path == "tests.fixtures.real_path.module_b.DefinedInModuleB"
예제 #15
0
def test_import_error():
    with pytest.raises(ImportError):
        get_object_tree("eeeeeeeeeeeeeeeeeee")