Skip to content

Commit

Permalink
Fix CI failing location tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Apr 28, 2024
1 parent 406300b commit f476eb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 50 deletions.
76 changes: 28 additions & 48 deletions tests/test_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

TEST_CASES_DIR = str(pathlib.Path(__file__).absolute().parent.joinpath('test_cases'))

DRIVE_REGEX = '(/[a-zA-Z]:|/)' if platform.system() == 'Windows' else ''
DRIVE_REGEX = '([a-zA-Z]:|)' if platform.system() == 'Windows' else ''

XML_WITH_NAMESPACES = '<pfa:root xmlns:pfa="http://xmlschema.test/nsa">\n' \
' <pfb:elem xmlns:pfb="http://xmlschema.test/nsb"/>\n' \
Expand Down Expand Up @@ -332,57 +332,37 @@ def test_normalize_url_hash_character(self):
self.assertRegex(url, f'{DRIVE_REGEX}/dir1/dir2/issue%20%23002/data.xml')

def test_normalize_url_with_query_part(self):
with patch.object(os, 'name', 'nt'):
self.assertEqual(os.name, 'nt')

url = "https://xmlschema.test/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url),
"https://xmlschema.test/schema%202/test.xsd?name=2%20id=3"
)
url = "https://xmlschema.test/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url),
"https://xmlschema.test/schema%202/test.xsd?name=2%20id=3"
)

url = "https://xmlschema.test/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url, method='html'),
"https://xmlschema.test/schema%202/test.xsd?name=2+id=3"
)
url = "https://xmlschema.test/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url, method='html'),
"https://xmlschema.test/schema%202/test.xsd?name=2+id=3"
)

url = "/path/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url),
"file:///path/schema%202/test.xsd"
)
url = "/path/schema 2/test.xsd?name=2 id=3"
self.assertRegex(
normalize_url(url),
f'file://{DRIVE_REGEX}/path/schema%202/test.xsd'
)

with patch.object(os, 'name', 'posix'):
self.assertEqual(os.name, 'posix')
self.assertRegex(
normalize_url('other.xsd?id=2', 'file:///home?name=2&id='),
f'file://{DRIVE_REGEX}/home/other.xsd'
)
self.assertRegex(
normalize_url('other.xsd#element', 'file:///home#attribute'),
f'file://{DRIVE_REGEX}/home/other.xsd'
)

url = "https://xmlschema.test/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url),
"https://xmlschema.test/schema%202/test.xsd?name=2%20id=3"
)

url = "https://xmlschema.test/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url, method='html'),
"https://xmlschema.test/schema%202/test.xsd?name=2+id=3"
)

url = "/path/schema 2/test.xsd?name=2 id=3"
self.assertEqual(
normalize_url(url),
"file:///path/schema%202/test.xsd"
)

self.check_url(normalize_url('other.xsd?id=2', 'file:///home?name=2&id='),
'file:///home/other.xsd')
self.check_url(normalize_url('other.xsd#element', 'file:///home#attribute'),
'file:///home/other.xsd')

self.check_url(normalize_url('other.xsd?id=2', 'https://host/path?name=2&id='),
'https://host/path/other.xsd?id=2')
self.check_url(normalize_url('other.xsd#element', 'https://host/path?name=2&id='),
'https://host/path/other.xsd#element')
self.check_url(normalize_url('other.xsd?id=2', 'https://host/path?name=2&id='),
'https://host/path/other.xsd?id=2')
self.check_url(normalize_url('other.xsd#element', 'https://host/path?name=2&id='),
'https://host/path/other.xsd#element')

def test_is_url_function(self):
self.assertTrue(is_url(self.col_xsd_file))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ def test_xml_resource_access(self):
with self.assertRaises(XMLResourceError) as ctx:
XMLResource(source, base_url=base_url, allow='sandbox')
self.assertEqual(
str(ctx.exception),
f"block access to out of sandbox file {normalize_url(source)}",
str(ctx.exception).lower(),
f"block access to out of sandbox file {normalize_url(source)}".lower(),
)

with self.assertRaises(TypeError) as ctx:
Expand Down

0 comments on commit f476eb7

Please sign in to comment.