Skip to content

Commit a6d3ae5

Browse files
authored
Merge pull request #52 from alexwlchan/add-tests
Add tests; fix a hyperlink issue
2 parents 8438e77 + 86554cb commit a6d3ae5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

aws/_common.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#!/usr/bin/env python3
2-
31
import functools
2+
import typing
43

54
import boto3
65
import hyperlink
@@ -73,8 +72,13 @@ def create_s3_session(s3_identifier, *, role_name="read_only"):
7372
return boto3.Session()
7473

7574

76-
def parse_s3_uri(s3_uri):
77-
uri = hyperlink.URL.from_text(s3_uri)
75+
class S3Uri(typing.TypedDict):
76+
Bucket: str
77+
Path: str
78+
79+
80+
def parse_s3_uri(s3_uri: str) -> S3Uri:
81+
uri = hyperlink.parse(s3_uri)
7882

7983
if uri.scheme != "s3":
8084
raise ValueError(f"Unrecognised scheme in {s3_uri!r}, expected s3://")

aws/test_common.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
from _common import parse_s3_uri
4+
5+
6+
def test_non_s3_uri_is_error():
7+
with pytest.raises(ValueError, match="Unrecognised scheme"):
8+
parse_s3_uri(s3_uri="https://www.example.com")
9+
10+
11+
def test_parses_s3_uri():
12+
assert parse_s3_uri(s3_uri="s3://example-bukkit/my/text/file.txt") == {
13+
"Bucket": "example-bukkit",
14+
"Path": "my/text/file.txt",
15+
}

0 commit comments

Comments
 (0)