Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cross-platfrom issues with test suite #529

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,9 +1317,9 @@ def normalize_paths(value, parent=os.curdir):
paths = []
for path in value.split(','):
path = path.strip()
if '/' in path:
if os.path.sep in path:
path = os.path.abspath(os.path.join(parent, path))
paths.append(path.rstrip('/'))
paths.append(path.rstrip(os.path.sep))
return paths


Expand Down
26 changes: 23 additions & 3 deletions testsuite/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
from testsuite.support import ROOT_DIR, PseudoFile


def safe_line_split(line):
""" parses the path, from message details """

# On certain platforms, the drive notation conflicts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, these comments can / should probably just move into the function docstring.

# with the message seperator, inducing problems during tuple unpacking.

split = line.split(':')
if 'win' in sys.platform:
if len(split) == 5:
drive, path, x, y, msg = split
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you leave comments explaining what kind of situation would result in having 5 items? (Likewise for the elif checking for a length of 4) Bonus points for an example in the comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that will be helpful as we continue to build up the windows support and verify that use case.

path = drive + ':' + path
elif len(split) == 4:
path, x, y, msg = split
else:
raise Exception("Unhandled edge case parsing message: " + line)
else:
path, x, y, msg = split
return path, x, y, msg


class ShellTestCase(unittest.TestCase):
"""Test the usual CLI options and output."""

Expand Down Expand Up @@ -77,7 +97,7 @@ def test_check_simple(self):
self.assertFalse(stderr)
self.assertEqual(len(stdout), 17)
for line, num, col in zip(stdout, (3, 6, 9, 12), (3, 6, 1, 5)):
path, x, y, msg = line.split(':')
path, x, y, msg = safe_line_split(line)
self.assertTrue(path.endswith(E11))
self.assertEqual(x, str(num))
self.assertEqual(y, str(col))
Expand Down Expand Up @@ -141,7 +161,7 @@ def test_check_diff(self):
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
for line, num, col in zip(stdout, (3, 6), (3, 6)):
path, x, y, msg = line.split(':')
path, x, y, msg = safe_line_split(line)
self.assertEqual(x, str(num))
self.assertEqual(y, str(col))
self.assertTrue(msg.startswith(' E11'))
Expand All @@ -154,7 +174,7 @@ def test_check_diff(self):
self.assertEqual(errcode, 1)
self.assertFalse(stderr)
for line, num, col in zip(stdout, (3, 6), (3, 6)):
path, x, y, msg = line.split(':')
path, x, y, msg = safe_line_split(line)
self.assertEqual(x, str(num))
self.assertEqual(y, str(col))
self.assertTrue(msg.startswith(' E11'))
Expand Down
16 changes: 11 additions & 5 deletions testsuite/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
import os
import unittest

import sys
from pycodestyle import normalize_paths


Expand All @@ -17,7 +17,13 @@ def test_normalize_paths(self):
self.assertEqual(normalize_paths('foo'), ['foo'])
self.assertEqual(normalize_paths('foo,bar'), ['foo', 'bar'])
self.assertEqual(normalize_paths('foo, bar '), ['foo', 'bar'])
self.assertEqual(normalize_paths('/foo/bar,baz/../bat'),
['/foo/bar', cwd + '/bat'])
self.assertEqual(normalize_paths(".pyc,\n build/*"),
['.pyc', cwd + '/build/*'])

if 'win' in sys.platform:
self.assertEqual(normalize_paths(r'C:\foo\bar,baz\..\bat'),
[r'C:\foo\bar', cwd + r'\bat'])
self.assertEqual(normalize_paths(".pyc"), ['.pyc'])
else:
self.assertEqual(normalize_paths('/foo/bar,baz/../bat'),
['/foo/bar', cwd + '/bat'])
self.assertEqual(normalize_paths(".pyc,\n build/*"),
['.pyc', cwd + '/build/*'])