From 677bee0e95f1ce89bfb0a178e535966d28954459 Mon Sep 17 00:00:00 2001 From: Bo Bayles Date: Thu, 18 May 2023 11:30:50 -0500 Subject: [PATCH] Add directory listing to URL class --- ada_url/ada_adapter.py | 3 +++ tests/test_ada_url.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/ada_url/ada_adapter.py b/ada_url/ada_adapter.py index 5dd53a1..96d24db 100644 --- a/ada_url/ada_adapter.py +++ b/ada_url/ada_adapter.py @@ -88,6 +88,9 @@ def __init__(self, url, base=None): if not lib.ada_is_valid(self.urlobj): raise ValueError('Invalid input') + def __dir__(self): + return super().__dir__() + list(PARSE_ATTRIBUTES) + def __getattr__(self, attr): if attr in GET_ATTRIBUTES: get_func = getattr(lib, f'ada_get_{attr}') diff --git a/tests/test_ada_url.py b/tests/test_ada_url.py index c8c13d0..8f33d49 100644 --- a/tests/test_ada_url.py +++ b/tests/test_ada_url.py @@ -8,6 +8,7 @@ parse_url, replace_url, ) +from ada_url.ada_adapter import GET_ATTRIBUTES class ADAURLTests(TestCase): @@ -86,6 +87,12 @@ def test_class_can_parse_with_base(self): actual = URL.can_parse(url, base) self.assertEqual(actual, expected) + def test_class_dir(self): + with URL('https://example.org') as urlobj: + actual = set(dir(urlobj)) + + self.assertTrue(actual.issuperset(GET_ATTRIBUTES)) + def test_check_url(self): for s, expected in ( ('https:example.org', True),