Skip to content

Commit

Permalink
Fix UNC path tests (issues #405 and #408)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Jul 29, 2024
1 parent 4ad7a48 commit 90a7233
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-xmlschema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8, 3.9, "3.10", 3.11, 3.12, "3.13.0-alpha.6", "pypy-3.10"]
python-version: [3.8, 3.9, "3.10", 3.11, 3.12, "3.13.0-beta.3", "pypy-3.10"]
exclude:
- os: macos-latest
python-version: 3.8
Expand All @@ -36,7 +36,7 @@ jobs:
python -m pip install --upgrade pip
pip install setuptools
- name: Install optional dependencies
if: ${{ matrix.python-version != '3.13.0-alpha.6' }}
if: ${{ matrix.python-version != '3.13.0-beta.3' }}
run: pip install lxml jinja2
- name: Test with unittest
run: |
Expand All @@ -48,5 +48,5 @@ jobs:
flake8 xmlschema --max-line-length=100 --statistics
- name: Lint with mypy
run: |
pip install mypy==1.10.0 elementpath==4.4.0 lxml-stubs
pip install mypy==1.11.0 elementpath==4.4.0 lxml-stubs
mypy --show-error-codes --strict xmlschema
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
CHANGELOG
*********

`v3.3.2`_ (2024-07-29)
======================
* Fix UNC path tests (issues #405 and #408)

`v3.3.1`_ (2024-04-27)
======================
* Update validation errors with logging stacktrace in debug mode
Expand Down Expand Up @@ -704,3 +708,4 @@ v0.9.6 (2017-05-05)
.. _v3.2.1: https://github.com/brunato/xmlschema/compare/v3.2.0...v3.2.1
.. _v3.3.0: https://github.com/brunato/xmlschema/compare/v3.2.1...v3.3.0
.. _v3.3.1: https://github.com/brunato/xmlschema/compare/v3.3.0...v3.3.1
.. _v3.3.2: https://github.com/brunato/xmlschema/compare/v3.3.1...v3.3.2
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
# The short X.Y version.
version = '3.3'
# The full version, including alpha/beta/rc tags.
release = '3.3.1'
release = '3.3.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
4 changes: 2 additions & 2 deletions publiccode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ publiccodeYmlVersion: '0.2'
name: xmlschema
url: 'https://github.com/sissaschool/xmlschema'
landingURL: 'https://github.com/sissaschool/xmlschema'
releaseDate: '2024-04-27'
softwareVersion: v3.3.1
releaseDate: '2024-07-29'
softwareVersion: v3.3.2
developmentStatus: stable
platforms:
- linux
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name='xmlschema',
version='3.3.1',
version='3.3.2',
packages=find_packages(include=['xmlschema*']),
package_data={
'xmlschema': ['py.typed', 'locale/**/*.mo', 'locale/**/*.po', 'schemas/*/*.xsd'],
Expand Down
25 changes: 19 additions & 6 deletions tests/test_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import pathlib
import platform
import sys

from urllib.parse import urlsplit, uses_relative
from pathlib import Path, PurePath, PureWindowsPath, PurePosixPath
Expand Down Expand Up @@ -280,7 +281,10 @@ def test_normalize_url_with_base_unc_path(self,):
self.assertEqual(url, 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')

url = normalize_url(r'dev\XMLSCHEMA\test.xsd', base_url=base_url_host_in_path)
self.assertEqual(url, 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')
if sys.version_info < (3, 12, 4):
self.assertEqual(url, 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')
else:
self.assertEqual(url, 'file://////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')

with patch.object(os, 'name', 'posix'):
self.assertEqual(os.name, 'posix')
Expand All @@ -294,7 +298,10 @@ def test_normalize_url_with_base_unc_path(self,):
self.assertEqual(url, 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')

url = normalize_url(r'dev/XMLSCHEMA/test.xsd', base_url=base_url_host_in_path)
self.assertEqual(url, 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')
if sys.version_info < (3, 12, 4):
self.assertEqual(url, 'file:////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')
else:
self.assertEqual(url, 'file://////filer01/MY_HOME/dev/XMLSCHEMA/test.xsd')

def test_normalize_url_slashes(self):
# Issue #116
Expand All @@ -311,10 +318,16 @@ def test_normalize_url_slashes(self):
self.assertRegex(normalize_url('/root/dir1/schema.xsd'),
f'file://{DRIVE_REGEX}/root/dir1/schema.xsd')

self.assertRegex(normalize_url('////root/dir1/schema.xsd'),
f'file://{DRIVE_REGEX}//root/dir1/schema.xsd')
self.assertRegex(normalize_url('dir2/schema.xsd', '////root/dir1'),
f'file://{DRIVE_REGEX}//root/dir1/dir2/schema.xsd')
if sys.version_info < (3, 12, 4):
self.assertRegex(normalize_url('////root/dir1/schema.xsd'),
f'file://{DRIVE_REGEX}//root/dir1/schema.xsd')
self.assertRegex(normalize_url('dir2/schema.xsd', '////root/dir1'),
f'file://{DRIVE_REGEX}//root/dir1/dir2/schema.xsd')
else:
self.assertRegex(normalize_url('////root/dir1/schema.xsd'),
f'file://{DRIVE_REGEX}////root/dir1/schema.xsd')
self.assertRegex(normalize_url('dir2/schema.xsd', '////root/dir1'),
f'file://{DRIVE_REGEX}////root/dir1/dir2/schema.xsd')

self.assertEqual(normalize_url('//root/dir1/schema.xsd'),
'file:////root/dir1/schema.xsd')
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ commands =

[testenv:mypy-py{38,39,310,311,312,py3}]
deps =
mypy==1.10.0
mypy==1.11.0
elementpath==4.4.0
lxml-stubs
jinja2
Expand All @@ -69,7 +69,7 @@ deps =
elementpath>=4.4.0, <5.0.0
lxml
jinja2
mypy==1.10.0
mypy==1.11.0
lxml-stubs
commands =
pytest tests -ra
Expand Down
2 changes: 1 addition & 1 deletion xmlschema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
XMLSchema, XMLSchema10, XMLSchema11, XsdComponent, XsdType, XsdElement, XsdAttribute
)

__version__ = '3.3.1'
__version__ = '3.3.2'
__author__ = "Davide Brunato"
__contact__ = "brunato@sissa.it"
__copyright__ = "Copyright 2016-2024, SISSA"
Expand Down
7 changes: 5 additions & 2 deletions xmlschema/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ def from_uri(cls, uri: str) -> 'LocationPath':
return LocationPosixPath(unquote(parts.path))

if parts.scheme == 'file':
if path.startswith('/') and ntpath.splitdrive(path[1:])[0]:
path_start = path[:4].replace('\\', '/')
if path_start.startswith(('////', '///')):
pass
elif path_start.startswith('/') and ntpath.splitdrive(path[1:])[0]:
return LocationWindowsPath(unquote(path[1:]))
elif path.startswith(('//', '/\\')) and ntpath.splitdrive(path[2:])[0]:
elif path_start.startswith('//') and ntpath.splitdrive(path[2:])[0]:
raise XMLSchemaValueError(f"Invalid URI {uri!r}")

if ntpath.splitdrive(path)[0] or '\\' in path:
Expand Down

0 comments on commit 90a7233

Please sign in to comment.