972.1.4
by Michael Terry
Add test_python3.py to test readiness of source code to run under python3 directly |
1 |
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
|
2 |
#
|
|
3 |
# Copyright 2014 Michael Terry <michael.terry@canonical.com>
|
|
4 |
#
|
|
5 |
# This file is part of duplicity.
|
|
6 |
#
|
|
7 |
# Duplicity is free software; you can redistribute it and/or modify it
|
|
8 |
# under the terms of the GNU General Public License as published by the
|
|
9 |
# Free Software Foundation; either version 2 of the License, or (at your
|
|
10 |
# option) any later version.
|
|
11 |
#
|
|
12 |
# Duplicity is distributed in the hope that it will be useful, but
|
|
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 |
# General Public License for more details.
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU General Public License
|
|
18 |
# along with duplicity; if not, write to the Free Software Foundation,
|
|
19 |
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 |
||
21 |
import os |
|
1305
by ken
* Patched in lp:~mterry/duplicity/giobackend-display-name |
22 |
import sys |
972.1.4
by Michael Terry
Add test_python3.py to test readiness of source code to run under python3 directly |
23 |
import subprocess |
1111.2.1
by Aaron Whitehouse
Fixed tox.ini to correctly run individual tests. Updated test_code.py to use unittest2 for Python versions < 2.7 (instead of failing). Improved testing directions in README-REPO. |
24 |
|
1305
by ken
* Patched in lp:~mterry/duplicity/giobackend-display-name |
25 |
if sys.version_info < (2, 7): |
26 |
import unittest2 as unittest # @UnresolvedImport @UnusedImport |
|
27 |
else: |
|
28 |
import unittest # @Reimport |
|
1102.18.1
by Aaron A Whitehouse
* Fix PEP-8 testing by moving to using pycodestyle library. |
29 |
|
1165
by Kenneth Loafman
Checkpoint: |
30 |
from . import _top_dir, DuplicityTestCase # @IgnorePep8 |
977.1.5
by Michael Terry
Add initial pep8 and pylint tests |
31 |
|
32 |
||
33 |
class CodeTest(DuplicityTestCase): |
|
34 |
||
1012
by Michael Terry
Some small testing fixes to work on older copies of mock and pylint |
35 |
def run_checker(self, cmd, returncodes=[0]): |
977.1.5
by Michael Terry
Add initial pep8 and pylint tests |
36 |
process = subprocess.Popen(cmd, |
37 |
stdout=subprocess.PIPE, |
|
38 |
stderr=subprocess.PIPE) |
|
39 |
output = process.communicate()[0] |
|
1012
by Michael Terry
Some small testing fixes to work on older copies of mock and pylint |
40 |
self.assertTrue(process.returncode in returncodes, output) |
977.1.5
by Michael Terry
Add initial pep8 and pylint tests |
41 |
self.assertEqual("", output, output) |
42 |
||
1023
by Kenneth Loafman
* Undid move of testing/test_code.py. Instead I fixed it |
43 |
@unittest.skipUnless(os.getenv('RUN_CODE_TESTS', None) == '1', |
44 |
'Must set environment var RUN_CODE_TESTS=1') |
|
972.1.4
by Michael Terry
Add test_python3.py to test readiness of source code to run under python3 directly |
45 |
def test_2to3(self): |
46 |
# As we modernize the source code, we can remove more and more nofixes
|
|
1061
by Kenneth Loafman
* Misc fixes for the following PEP8 issues: |
47 |
self.run_checker([ |
48 |
"2to3", |
|
49 |
"--nofix=next", |
|
50 |
"--nofix=types", |
|
51 |
"--nofix=unicode", |
|
52 |
# The following fixes we don't want to remove, since they are false
|
|
53 |
# positives, things we don't care about, or real incompatibilities
|
|
54 |
# but which 2to3 can fix for us better automatically.
|
|
55 |
"--nofix=callable", |
|
56 |
"--nofix=dict", |
|
57 |
"--nofix=future", |
|
58 |
"--nofix=imports", |
|
59 |
"--nofix=print", |
|
60 |
"--nofix=raw_input", |
|
61 |
"--nofix=urllib", |
|
62 |
"--nofix=xrange", |
|
63 |
_top_dir]) |
|
977.1.5
by Michael Terry
Add initial pep8 and pylint tests |
64 |
|
1023
by Kenneth Loafman
* Undid move of testing/test_code.py. Instead I fixed it |
65 |
@unittest.skipUnless(os.getenv('RUN_CODE_TESTS', None) == '1', |
66 |
'Must set environment var RUN_CODE_TESTS=1') |
|
977.1.5
by Michael Terry
Add initial pep8 and pylint tests |
67 |
def test_pylint(self): |
1113.2.1
by Aaron Whitehouse
Fixed 2to3 issues. Updated README-REPO with more test information. Updated pylint and test_diff2 descriptions to make it clear these require packages to be installed on the system to pass. All tests pass on Python 2.6 and Python 2.7 as at this revision. |
68 |
"""Pylint test (requires pylint to be installed to pass)"""
|
1061
by Kenneth Loafman
* Misc fixes for the following PEP8 issues: |
69 |
self.run_checker([ |
70 |
"pylint", |
|
71 |
"-E", |
|
72 |
"--msg-template={msg_id}: {line}: {msg}", |
|
73 |
"--disable=E0203", # Access to member before its definition line |
|
74 |
"--disable=E0602", # Undefined variable |
|
75 |
"--disable=E0611", # No name in module |
|
76 |
"--disable=E1101", # Has no member |
|
77 |
"--disable=E1103", # Maybe has no member |
|
1134
by Kenneth Loafman
* Upgrade to newest version of pep8 and pylint. Add three ignores |
78 |
"--disable=E0712", # Catching an exception which doesn't inherit from BaseException |
1061
by Kenneth Loafman
* Misc fixes for the following PEP8 issues: |
79 |
"--ignore=_librsync.so", |
1134
by Kenneth Loafman
* Upgrade to newest version of pep8 and pylint. Add three ignores |
80 |
"--msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'", |
1061
by Kenneth Loafman
* Misc fixes for the following PEP8 issues: |
81 |
os.path.join(_top_dir, 'duplicity'), |
82 |
os.path.join(_top_dir, 'bin/duplicity'), |
|
83 |
os.path.join(_top_dir, 'bin/rdiffdir')], |
|
84 |
# Allow usage errors, older versions don't have
|
|
85 |
# --msg-template
|
|
86 |
[0, 32]) |
|
977.1.5
by Michael Terry
Add initial pep8 and pylint tests |
87 |
|
1023
by Kenneth Loafman
* Undid move of testing/test_code.py. Instead I fixed it |
88 |
@unittest.skipUnless(os.getenv('RUN_CODE_TESTS', None) == '1', |
89 |
'Must set environment var RUN_CODE_TESTS=1') |
|
977.1.5
by Michael Terry
Add initial pep8 and pylint tests |
90 |
def test_pep8(self): |
1305
by ken
* Patched in lp:~mterry/duplicity/giobackend-display-name |
91 |
ignores = [ |
92 |
"E402", # module level import not at top of file |
|
93 |
"E731", # do not assign a lambda expression, use a def |
|
94 |
]
|
|
95 |
self.run_checker(["pep8", |
|
96 |
"--ignore=" + ','.join(ignores), |
|
97 |
"--max-line-length=120", |
|
98 |
os.path.join(_top_dir, 'duplicity'), |
|
99 |
os.path.join(_top_dir, 'bin/duplicity'), |
|
100 |
os.path.join(_top_dir, 'bin/rdiffdir')]) |
|
101 |
||
972.1.4
by Michael Terry
Add test_python3.py to test readiness of source code to run under python3 directly |
102 |
|
103 |
if __name__ == "__main__": |
|
104 |
unittest.main() |