sissaschool / xmlschema

XML Schema validator and data conversion library for Python
MIT License
404 stars 75 forks source link

normalize_url test failures with Python 3.12 #405

Closed ckastner closed 3 weeks ago

ckastner commented 1 month ago

Hi,

with Python 3.12, I'm seeing the following test failures:

======================================================================
FAIL: test_normalize_url_slashes (tests.test_locations.TestLocations.test_normalize_url_slashes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/python-xmlschema-3.3.1/tests/test_locations.py", line 314, in test_normalize_url_slashes
    self.assertRegex(normalize_url('////root/dir1/schema.xsd'),
AssertionError: Regex didn't match: 'file:////root/dir1/schema.xsd' not found in 'file://////root/dir1/schema.xsd'

======================================================================
FAIL: test_normalize_url_with_base_unc_path (tests.test_locations.TestLocations.test_normalize_url_with_base_unc_path)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/python-xmlschema-3.3.1/tests/test_locations.py", line 283, in test_normalize_url_with_base_unc_path
    self.assertEqual(url, 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')
AssertionError: 'file://///filer01/MY_HOME/dev/XMLSCHEMA/test.xsd' != 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd'
- file://///filer01/MY_HOME/dev/XMLSCHEMA/test.xsd
?      -
+ file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd

Looking at the changelog of 3.12, there were a few changes to urllib, though it's not immediately obvious to me which one could have affected this (or if these change even were the cause).

brunato commented 1 month ago

Hi, the problem is with Python 3.12.4 and Python 3.13.0b3, that fix path processing with URN like paths "//" (without scheme). It's a minor change in urlunsplit(), but probably the major impact is giving back the URL from parts:

class SplitResult(_SplitResultBase, _NetlocResultMixinStr):
    __slots__ = ()
    def geturl(self):
        return urlunsplit(self)

I will check if it can have an impact on URN processing.

thank you

brunato commented 3 weeks ago

v3.3.2 fixes the problem with failing tests. A change in LocationPath.from_uri() has been necessary for fixing the 2nd test.

Both tests are now version dependent (the change of urlunsplit with UNC paths is in Python 3.12.4).

Thank you