Skip to content

Commit

Permalink
Fix tests to pass on Python 3
Browse files Browse the repository at this point in the history
Fix tests to pass on Python 3

Drop Python 2.6

Restore tests to pass on Python 2.7

Fix missing iteritems on Python 3

Sort imports

Drop Python 3.3

Fix hasattr

Refactor to convert bytes to strings only in utils

Fix i18ndude script location

Fix i18ndude script location
  • Loading branch information
datakurre committed Nov 20, 2014
1 parent bea6218 commit 78d7a22
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 26 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
@@ -1,11 +1,13 @@
language: python
python: 2.7
python:
- 2.7
- 3.4
env:
matrix:
- CONF=travis.cfg
- CONF=extras.cfg EXTRAS_INSTALLED=true
install:
- python bootstrap.py -v 1.7.1
- python bootstrap.py
- bin/buildout -c $CONF annotate
- bin/buildout -N -t 3 -c $CONF
script:
Expand Down
9 changes: 5 additions & 4 deletions buildout.cfg
Expand Up @@ -40,6 +40,7 @@ deprecated-aliases = True
flake8-max-complexity = 12
imports = True
jshint = False
jshint-bin = ${buildout:directory}/bin/jshint
pep3101 = False
prefer-single-quotes = True
return-status-codes = False
Expand All @@ -58,9 +59,9 @@ eggs =
zest.releaser

[versions]
setuptools = 0.9.8
distribute = 0.6.49
zc.buildout = 1.7.1
zc.recipe.egg = 1.3.2
setuptools =
distribute =
zc.buildout =
zc.recipe.egg =
zope.testrunner = 4.0.4
transaction = 1.2.0
6 changes: 5 additions & 1 deletion plone/recipe/codeanalysis/deprecated_aliases.py
Expand Up @@ -66,7 +66,11 @@ def _code_analysis_deprecated_aliases_lines_parser(lines, file_path):
if line.find('# noqa') != -1:
continue

for newer_version, old_alias in deprecated_aliases.iteritems():
try:
deprecated_aliases_iteritems = deprecated_aliases.iteritems()
except AttributeError:
deprecated_aliases_iteritems = deprecated_aliases.items() # PY3
for newer_version, old_alias in deprecated_aliases_iteritems:
for alias in old_alias:
if line.find(alias) != -1:
errors.append(msg.format(
Expand Down
2 changes: 1 addition & 1 deletion plone/recipe/codeanalysis/imports.py
Expand Up @@ -76,7 +76,7 @@ def _code_analysis_imports_sorting(lines, relative_path):

# duplicate imports list and sort it
imports_sorted = imports[:]
imports_sorted.sort(lambda a, b: cmp(a[1], b[1]))
imports_sorted.sort(key=lambda x: x[1])

if imports_sorted != imports:
errors.append('{0}:{1}-{2}: found unsorted imports'.format(
Expand Down
2 changes: 1 addition & 1 deletion plone/recipe/codeanalysis/tests/i18ndude.rst
Expand Up @@ -14,7 +14,7 @@ i18ndude code analysis is included by default::
... """
... )
>>> buildout_output_lower = system(buildout).lower()
>>> open('/tmp/output.txt', 'w').write(buildout_output_lower)
>>> output = open('/tmp/output.txt', 'w').write(buildout_output_lower)

find-untranslated code analysis script has been created::

Expand Down
10 changes: 7 additions & 3 deletions plone/recipe/codeanalysis/tests/test_csslint.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from io import open
from os.path import isfile as path_isfile
from os.path import join as path_join
from plone.recipe.codeanalysis.csslint import code_analysis_csslint
Expand All @@ -14,13 +16,15 @@ def setUp(self):
'csslint-bin': 'bin/csslint',
'jenkins': 'False'
}
if path_isfile('../../bin/csslint'): # when cwd is parts/test
self.options['csslint-bin'] = '../../bin/csslint'
self.test_dir = mkdtemp()

def tearDown(self):
rmtree(self.test_dir)

def test_analysis_should_return_false_when_error_found(self):
incorrect_code = file(path_join(self.test_dir, 'incorrect.css'), 'w')
incorrect_code = open(path_join(self.test_dir, 'incorrect.css'), 'w')
incorrect_code.write(
'a:link {color: blue}\n'
'{}\n'
Expand All @@ -38,7 +42,7 @@ def test_analysis_should_return_false_when_oserror(self):
self.assertFalse(code_analysis_csslint(self.options))

def test_analysis_should_return_true(self):
correct_code = file(path_join(self.test_dir, 'correct.css'), 'w')
correct_code = open(path_join(self.test_dir, 'correct.css'), 'w')
correct_code.write(
'a:link {color:blue}\n'
'h3 {color: red}\n'
Expand All @@ -49,7 +53,7 @@ def test_analysis_should_return_true(self):

def test_analysis_file_should_exist_when_jenkins_is_true(self):
location_tmp_dir = mkdtemp()
correct_code = file(path_join(self.test_dir, 'correct.css'), 'w')
correct_code = open(path_join(self.test_dir, 'correct.css'), 'w')
correct_code.write(
'a:link {color:blue}\n'
'h3 {color: red}\n'
Expand Down
10 changes: 7 additions & 3 deletions plone/recipe/codeanalysis/tests/test_flake8.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from io import open
from os.path import isfile as path_isfile
from os.path import join as path_join
from plone.recipe.codeanalysis.flake8 import code_analysis_flake8
Expand All @@ -17,13 +19,15 @@ def setUp(self):
'flake8-max-line-length': '79',
'jenkins': 'False'
}
if path_isfile('../../bin/flake8'): # when cwd is parts/test
self.options['bin-directory'] = '../../bin/'
self.test_dir = mkdtemp()

def tearDown(self):
rmtree(self.test_dir)

def test_analysis_should_return_false_when_error_found(self):
incorrect_code = file(path_join(self.test_dir, 'incorrect.py'), 'w')
incorrect_code = open(path_join(self.test_dir, 'incorrect.py'), 'w')
incorrect_code.write(
'import sys\n'
'class MyClass():\n'
Expand All @@ -41,7 +45,7 @@ def test_analysis_should_return_false_when_oserror(self):
self.assertFalse(code_analysis_flake8(self.options))

def test_analysis_should_return_true(self):
correct_code = file(path_join(self.test_dir, 'correct.py'), 'w')
correct_code = open(path_join(self.test_dir, 'correct.py'), 'w')
correct_code.write(
'class MyClass():\n'
' def __init__(self):\n'
Expand All @@ -53,7 +57,7 @@ def test_analysis_should_return_true(self):

def test_analysis_file_should_exist_when_jenkins_is_true(self):
location_tmp_dir = mkdtemp()
correct_code = file(path_join(self.test_dir, 'correct.py'), 'w')
correct_code = open(path_join(self.test_dir, 'correct.py'), 'w')
correct_code.write(
'class MyClass():\n'
' def __init__(self):\n'
Expand Down
2 changes: 2 additions & 0 deletions plone/recipe/codeanalysis/tests/test_i18ndude.py
Expand Up @@ -34,6 +34,8 @@ def setUp(self):
'find-untranslated': 'True',
'i18ndude-bin': 'bin/i18ndude',
}
if os.path.isfile('../../bin/i18ndude'): # when cwd is parts/test
self.options['i18ndude-bin'] = '../../bin/i18ndude'
self.test_dir = mkdtemp()

def tearDown(self):
Expand Down
12 changes: 8 additions & 4 deletions plone/recipe/codeanalysis/tests/test_jscs.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from io import open
from os.path import isfile as path_isfile
from os.path import join as path_join
from plone.recipe.codeanalysis.jscs import code_analysis_jscs
Expand Down Expand Up @@ -63,21 +65,23 @@ def setUp(self):
'jscs-exclude': '',
'jenkins': 'False'
}
if path_isfile('../../bin/jscs'): # when cwd is parts/test
self.options['jscs-bin'] = '../../bin/jscs'
self.test_dir = mkdtemp()

def tearDown(self):
rmtree(self.test_dir)

def test_analysis_should_return_false_when_error_found(self):
full_path = path_join(self.test_dir, 'incorrect.js')
with file(full_path, 'w') as incorrect_code:
with open(full_path, 'w') as incorrect_code:
incorrect_code.write(INCORRECT_FILE)
self.options['directory'] = self.test_dir
self.assertFalse(code_analysis_jscs(self.options))

def test_analysis_should_return_true_when_invalid_file_is_excluded(self):
full_path = path_join(self.test_dir, 'incorrect.js')
with file(full_path, 'w') as incorrect_code:
with open(full_path, 'w') as incorrect_code:
incorrect_code.write(INCORRECT_FILE)
self.options['directory'] = self.test_dir
self.options['jscs-exclude'] = full_path
Expand All @@ -92,15 +96,15 @@ def test_analysis_should_return_false_when_oserror(self):

def test_analysis_should_return_true(self):
full_path = path_join(self.test_dir, 'correct.js')
with file(full_path, 'w') as correct_code:
with open(full_path, 'w') as correct_code:
correct_code.write(CORRECT_FILE)
self.options['directory'] = self.test_dir
self.assertTrue(code_analysis_jscs(self.options))

def test_analysis_file_should_exist_when_jenkins_is_true(self):
location_tmp_dir = mkdtemp()
full_path = path_join(self.test_dir, 'correct.js')
with file(full_path, 'w') as correct_code:
with open(full_path, 'w') as correct_code:
correct_code.write(CORRECT_FILE)
self.options['directory'] = self.test_dir
self.options['location'] = location_tmp_dir
Expand Down
15 changes: 10 additions & 5 deletions plone/recipe/codeanalysis/tests/test_jshint.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from io import open
from os.path import isfile as path_isfile
from os.path import join as path_join
from plone.recipe.codeanalysis.jshint import code_analysis_jshint
Expand Down Expand Up @@ -66,21 +68,24 @@ def setUp(self):
'jshint-exclude': '',
'jenkins': 'False'
}
if path_isfile('../../bin/jshint'): # when cwd is parts/test
self.options['jshint-bin'] = '../../bin/jshint'

self.test_dir = mkdtemp()

def tearDown(self):
rmtree(self.test_dir)

def test_analysis_should_return_false_when_error_found(self):
full_path = path_join(self.test_dir, 'incorrect.js')
with file(full_path, 'w') as incorrect_code:
with open(full_path, 'w') as incorrect_code:
incorrect_code.write(INCORRECT_FILE)
self.options['directory'] = self.test_dir
self.assertFalse(code_analysis_jshint(self.options))

def test_analysis_should_output_warnings(self):
full_path = path_join(self.test_dir, 'warnings.js')
with file(full_path, 'w') as warnings_code:
with open(full_path, 'w') as warnings_code:
warnings_code.write(WARNINGS_FILE)
self.options['directory'] = self.test_dir
expected_output = EXPECTED_WARNINGS_OUTPUT.format(self.options)
Expand All @@ -89,7 +94,7 @@ def test_analysis_should_output_warnings(self):

def test_analysis_should_return_true_for_warnings(self):
full_path = path_join(self.test_dir, 'warnings.js')
with file(full_path, 'w') as warnings_code:
with open(full_path, 'w') as warnings_code:
warnings_code.write(WARNINGS_FILE)
self.options['directory'] = self.test_dir
self.assertTrue(code_analysis_jshint(self.options))
Expand All @@ -103,15 +108,15 @@ def test_analysis_should_return_false_when_oserror(self):

def test_analysis_should_return_true(self):
full_path = path_join(self.test_dir, 'correct.js')
with file(full_path, 'w') as correct_code:
with open(full_path, 'w') as correct_code:
correct_code.write(CORRECT_FILE)
self.options['directory'] = self.test_dir
self.assertTrue(code_analysis_jshint(self.options))

def test_analysis_file_should_exist_when_jenkins_is_true(self):
location_tmp_dir = mkdtemp()
full_path = path_join(self.test_dir, 'correct.js')
with file(full_path, 'w') as correct_code:
with open(full_path, 'w') as correct_code:
correct_code.write(CORRECT_FILE)
self.options['directory'] = self.test_dir
self.options['location'] = location_tmp_dir
Expand Down
2 changes: 2 additions & 0 deletions plone/recipe/codeanalysis/tests/test_zptlint.py
Expand Up @@ -34,6 +34,8 @@ def setUp(self):
'zptlint': 'True',
'zptlint-bin': 'bin/zptlint',
}
if os.path.isfile('../../bin/zptlint'): # when cwd is parts/test
self.options['zptlint-bin'] = '../../bin/zptlint'
self.test_dir = mkdtemp()

def tearDown(self):
Expand Down
5 changes: 4 additions & 1 deletion plone/recipe/codeanalysis/utils.py
Expand Up @@ -40,7 +40,10 @@ def find_files(options, regex):
stdout=subprocess.PIPE
)
files, err = process_files.communicate()
return files
if isinstance(files, bytes):
return files.decode('utf-8')
else:
return files


def read_subprocess_output(cmd, output_file):
Expand Down
6 changes: 5 additions & 1 deletion travis.cfg
@@ -1,6 +1,10 @@
[buildout]
extends = buildout.cfg
parts += createcoverage
parts =
node
test
code-analysis
createcoverage

[code-analysis]
pre-commit-hook = False
Expand Down

0 comments on commit 78d7a22

Please sign in to comment.