Skip to content

Add __str__ and __repr__ methods #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ada_url/ada_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ def __setattr__(self, attr, value):

return super().__setattr__(attr, value)

def __str__(self):
return self.href

def __repr__(self):
return f'<URL "{self.href}">'

@staticmethod
def can_parse(url, base=None):
try:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_ada_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ def test_class_dir(self):
actual = set(dir(urlobj))
self.assertTrue(actual.issuperset(GET_ATTRIBUTES))

def test_to_str(self):
urlobj = URL('https://example.org/../something.txt')
actual = str(urlobj)
expected = 'https://example.org/something.txt'
self.assertEqual(actual, expected)

def test_to_repr(self):
urlobj = URL('https://example.org/../something.txt')
actual = repr(urlobj)
expected = '<URL "https://example.org/something.txt">'
self.assertEqual(actual, expected)

def test_check_url(self):
for s, expected in (
('https:example.org', True),
Expand Down