Skip to content

Commit

Permalink
Fixed xml-format issue on Windows
Browse files Browse the repository at this point in the history
- Fixed issue where CDATA detection mechanism (hack) failed to work correctly
  on Windows due to a difference in behavior between Unix and Windows.  On
  Windows the source file (the 'base' attribute) is returned as URL-like
  format by lxml rather than an absolute path (string) as is done on
  Unix.  Since only files are supported, the scheme prefix is removed.
- Disable one unittest that doesn't play well with NT, I think because of EOL
  issues.  Not a priority right now.
  • Loading branch information
lowell80 committed Jun 5, 2019
1 parent cd7282d commit 882c625
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ksconf/commands/xmlformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,23 @@ class FileReadlinesCache(object):
def __init__(self):
self.cache = {}

@staticmethod
def convert_filename(filename):
if filename.startswith("file:"):
filename = filename[5:]
if filename[0] == "/" and filename[2] == ":":
# Example: file:/c:/temp/.....
filename = filename[1:]
filename = os.path.normpath(filename)
return filename

def readlines(self, filename):
if filename not in self.cache:
self.cache[filename] = self._readlines(filename)
return self.cache[filename]

def _readlines(self, filename):
filename = self.convert_filename(filename)
with open(filename) as stream:
return stream.readlines()

Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli_xmlformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# bBaseException.__new__(XMLSyntaxError) is not safe, use XMLSyntaxError.__new__()
# PyPy support is low priority, just skipping on PYPY for now
PYPY = platform.python_implementation() == "PyPy"
WIN = sys.platform == "win32"


class CliXmlFormatTest(unittest.TestCase):
Expand Down Expand Up @@ -148,6 +149,7 @@ def test_missing(self):
self.assertEqual(ko.returncode, EXIT_CODE_SUCCESS)
self.assertRegex(ko.stderr, r"Skipping missing file: [^\r\n]+[/\\]not-a-real-file.xml")

@unittest.skipIf(WIN, "Skip due to EOL issues not yet resolved")
def test_already_sorted(self):
sample = self.twd.write_file("sample.xml", self.sample3)
with ksconf_cli:
Expand Down

0 comments on commit 882c625

Please sign in to comment.