Example #1
0
def test_can_parse_empty_path():
    path = Path("")
    assert str(path) == ""
    assert path.string == ""
Example #2
0
def test_can_remove_dot_segments_pattern_2():
    path_in = Path("mid/content=5/../6")
    path_out = path_in.remove_dot_segments()
    assert path_out == "mid/6"
Example #3
0
def test_can_parse_none_path():
    path = Path(None)
    assert str(path) == ""
    assert path.string is None
Example #4
0
def test_path_equality_when_none():
    path = Path(None)
    none = None
    assert path == none
Example #5
0
def test_path_has_no_segments_when_none():
    path = Path(None)
    segments = list(path.segments)
    assert segments == []
Example #6
0
def test_can_parse_path_with_encoded_slash():
    path = Path("/foo/bar%2Fbaz")
    assert str(path) == "/foo/bar%2Fbaz"
    assert path.string == "/foo/bar%2Fbaz"
Example #7
0
def test_path_inequality():
    path1 = Path("/foo/bar")
    path2 = Path("/foo/bar/baz")
    assert path1 != path2
Example #8
0
def test_can_add_trailing_slash_to_empty_path():
    path = Path("")
    path = path.with_trailing_slash()
    assert path.string == "/"
Example #9
0
def test_cant_add_trailing_slash_to_none_path():
    path = Path(None)
    path = path.with_trailing_slash()
    assert path.string is None
Example #10
0
def test_wont_add_trailing_slash_to_path_that_already_has_one():
    path = Path("/foo/bar/")
    path = path.with_trailing_slash()
    assert path.string == "/foo/bar/"
Example #11
0
def test_wont_add_trailing_slash_to_root_path():
    path = Path("/")
    path = path.with_trailing_slash()
    assert path.string == "/"
Example #12
0
def test_can_add_trailing_slash_to_path():
    path = Path("/foo/bar")
    path = path.with_trailing_slash()
    assert path.string == "/foo/bar/"
Example #13
0
def test_can_remove_dot_segments_when_starts_with_double_dot():
    path_in = Path("../a")
    path_out = path_in.remove_dot_segments()
    assert path_out == "a"
Example #14
0
def test_can_remove_dot_segments_when_single_dot():
    path_in = Path(".")
    path_out = path_in.remove_dot_segments()
    assert path_out == ""
Example #15
0
def test_can_parse_absolute_path():
    path = Path("/foo/bar")
    assert str(path) == "/foo/bar"
    assert path.string == "/foo/bar"
Example #16
0
def test_can_remove_trailing_slash_from_path():
    path = Path("/foo/bar/")
    path = path.without_trailing_slash()
    assert path.string == "/foo/bar"
Example #17
0
def test_can_parse_relative_path():
    path = Path("foo/bar")
    assert str(path) == "foo/bar"
    assert path.string == "foo/bar"
Example #18
0
def test_wont_remove_trailing_slash_if_none_exists():
    path = Path("/foo/bar")
    path = path.without_trailing_slash()
    assert path.string == "/foo/bar"
Example #19
0
def test_path_equality():
    path1 = Path("/foo/bar")
    path2 = Path("/foo/bar")
    assert path1 == path2
Example #20
0
def test_will_remove_root_path_slash():
    path = Path("/")
    path = path.without_trailing_slash()
    assert path.string == ""
Example #21
0
def test_path_equality_with_string_containing_encoded_space():
    path = Path("/foo bar")
    string = "/foo%20bar"
    assert path == string
Example #22
0
def test_cannot_remove_trailing_slash_from_empty_string():
    path = Path("")
    path = path.without_trailing_slash()
    assert path.string == ""
Example #23
0
def test_path_is_hashable():
    path = Path("/foo/bar")
    hashed = hash(path)
    assert hashed
Example #24
0
def test_cannot_remove_trailing_slash_from_none_path():
    path = Path(None)
    path = path.without_trailing_slash()
    assert path.string is None
Example #25
0
def test_path_is_iterable_as_segments():
    path = Path("/foo/bar")
    segments = list(path)
    assert segments == ["", "foo", "bar"]
Example #26
0
def test_can_remove_dot_segments_pattern_1():
    path_in = Path("/a/b/c/./../../g")
    path_out = path_in.remove_dot_segments()
    assert path_out == "/a/g"