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

Output path tests and abspaths for windows #299

Merged
merged 3 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions prospector/config/datatype.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
import os
import sys

from setoptconf.datatype import Choice

Expand All @@ -7,5 +9,11 @@ class OutputChoice(Choice):
def sanitize(self, value):
parsed = re.split(r'[;:]', value)
output_format, output_targets = parsed[0], parsed[1:]
validated_format = super(OutputChoice, self).sanitize(output_format)
return (output_format, output_targets)
checked_targets = []
for i, target in enumerate(output_targets):
if sys.platform.startswith('win') and target.startswith((os.path.sep, os.path.altsep)):
checked_targets[-1] += ':'+target
else:
checked_targets.append(target)
validated_format = super(OutputChoice, self).sanitize(output_format)
return (validated_format, checked_targets)
Empty file added tests/config/__init__.py
Empty file.
114 changes: 114 additions & 0 deletions tests/config/test_datatype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import sys
from unittest import TestCase

from prospector.config.datatype import OutputChoice

if sys.version_info >= (3, 0):
from unittest.mock import patch
else:
from mock import patch


class TestOutputChoice(TestCase):

@patch('sys.platform', 'linux')
@patch('os.path.sep', '/')
@patch('os.path.altsep', None)
def test_sanitize_rel_path_colon_posix(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit:./test-results.xml'), ('xunit', ['./test-results.xml']))

@patch('sys.platform', 'linux')
@patch('os.path.sep', '/')
@patch('os.path.altsep', None)
def test_sanitize_rel_path_semicolon_posix(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit;./test-results.xml'), ('xunit', ['./test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_rel_path_colon_windows(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit:.\\test-results.xml'), ('xunit', ['.\\test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_rel_path_semicolon_windows(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit;.\\test-results.xml'), ('xunit', ['.\\test-results.xml']))

@patch('sys.platform', 'linux')
@patch('os.path.sep', '/')
@patch('os.path.altsep', None)
def test_sanitize_abs_path_colon_posix(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit:/home/test-results.xml'), ('xunit', ['/home/test-results.xml']))

@patch('sys.platform', 'linux')
@patch('os.path.sep', '/')
@patch('os.path.altsep', None)
def test_sanitize_abs_path_semicolon_posix(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit;/home/test-results.xml'), ('xunit', ['/home/test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_abs_path_colon_windows(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit:C:\\testResults\\test-results.xml'), ('xunit', ['C:\\testResults\\test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_abs_path_semicolon_windows(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit;C:\\testResults\\test-results.xml'), ('xunit', ['C:\\testResults\\test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_abs_path_colon_windows_alternate(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit:C:/testResults/test-results.xml'), ('xunit', ['C:/testResults/test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_abs_path_semicolon_windows_alternate(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit;C:/testResults/test-results.xml'), ('xunit', ['C:/testResults/test-results.xml']))

@patch('sys.platform', 'linux')
@patch('os.path.sep', '/')
@patch('os.path.altsep', None)
def test_sanitize_abs_rel_path_colon_posix(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit:/home/test-results.xml:./test-results.xml'),
('xunit', ['/home/test-results.xml', './test-results.xml']))

@patch('sys.platform', 'linux')
@patch('os.path.sep', '/')
@patch('os.path.altsep', None)
def test_sanitize_abs_rel_path_semicolon_posix(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit;/home/test-results.xml;./test-results.xml'),
('xunit', ['/home/test-results.xml', './test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_abs_rel_path_colon_windows(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit:C:\\home\\test-results.xml:.\\test-results.xml'),
('xunit', ['C:\\home\\test-results.xml', '.\\test-results.xml']))

@patch('sys.platform', 'win32')
@patch('os.path.sep', '\\')
@patch('os.path.altsep', '/')
def test_sanitize_abs_rel_path_semicolon_windows(self):
output_choice = OutputChoice(['xunit'])
self.assertEqual(output_choice.sanitize('xunit;C:\\home\\test-results.xml;.\\test-results.xml'),
('xunit', ['C:\\home\\test-results.xml', '.\\test-results.xml']))