Skip to content

Commit 51fc990

Browse files
authored
Adds pylint script to .travis.yml (google#38)
1 parent 4198d5a commit 51fc990

18 files changed

+81
-59
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ python:
66
- "3.6"
77
before_install:
88
- pip install --upgrade setuptools pip
9+
- pip install --upgrade pylint pytest pytest-pylint pytest-runner
910
install:
1011
- python setup.py develop
11-
script: nosetests --ignore-files=parser_fuzz_test.py --exclude=test_components_py3.py
12+
script:
13+
- python -m pytest
14+
- if [[ $TRAVIS_PYTHON_VERSION != 3.6 ]]; then pylint fire --ignore=test_components_py3.py,parser_fuzz_test.py; fi

examples/__init__.py

Whitespace-only changes.

examples/cipher/__init__.py

Whitespace-only changes.

examples/cipher/cipher_test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Tests for the cipher module."""
16+
1517
from fire import testutils
1618

17-
from fire.examples.cipher import cipher
19+
from examples.cipher import cipher
1820

1921

2022
class CipherTest(testutils.BaseTestCase):

examples/diff/__init__.py

Whitespace-only changes.

examples/diff/diff_test.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Tests for the diff and difffull modules."""
16+
1517
import tempfile
1618

1719
from fire import testutils
1820

19-
from fire.examples.diff import diff
20-
from fire.examples.diff import difffull
21+
from examples.diff import diff
22+
from examples.diff import difffull
2123

2224

2325
class DiffTest(testutils.BaseTestCase):
@@ -30,8 +32,8 @@ def setUp(self):
3032
self.file1 = file1 = tempfile.NamedTemporaryFile()
3133
self.file2 = file2 = tempfile.NamedTemporaryFile()
3234

33-
file1.write('test\ntest1\n')
34-
file2.write('test\ntest2\nextraline\n')
35+
file1.write(b'test\ntest1\n')
36+
file2.write(b'test\ntest2\nextraline\n')
3537

3638
file1.flush()
3739
file2.flush()

examples/identity/__init__.py

Whitespace-only changes.

examples/widget/__init__.py

Whitespace-only changes.

examples/widget/collector.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import fire
1818

19-
from fire.examples.widget import widget
19+
from examples.widget import widget
2020

2121

2222
class Collector(object):
@@ -28,7 +28,7 @@ def __init__(self):
2828

2929
def collect_widgets(self):
3030
"""Returns all the widgets the Collector wants."""
31-
return [widget.Widget() for _ in xrange(self.desired_widget_count)]
31+
return [widget.Widget() for _ in range(self.desired_widget_count)]
3232

3333

3434
def main():

examples/widget/collector_test.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Tests for the collector module."""
16+
1517
from fire import testutils
1618

17-
from fire.examples.widget import collector
18-
from fire.examples.widget import widget
19+
from examples.widget import collector
20+
from examples.widget import widget
1921

2022

2123
class CollectorTest(testutils.BaseTestCase):
@@ -26,11 +28,11 @@ def testCollectorHasWidget(self):
2628

2729
def testCollectorWantsMoreWidgets(self):
2830
col = collector.Collector()
29-
self.assertEquals(col.desired_widget_count, 10)
31+
self.assertEqual(col.desired_widget_count, 10)
3032

3133
def testCollectorGetsWantedWidgets(self):
3234
col = collector.Collector()
33-
self.assertEquals(len(col.collect_widgets()), 10)
35+
self.assertEqual(len(col.collect_widgets()), 10)
3436

3537

3638
if __name__ == '__main__':

examples/widget/widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Widget(object):
2121

2222
def whack(self, n=1):
2323
"""Prints "whack!" n times."""
24-
return ' '.join('whack!' for _ in xrange(n))
24+
return ' '.join('whack!' for _ in range(n))
2525

2626
def bang(self, noise='bang'):
2727
"""Makes a loud noise."""

examples/widget/widget_test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Tests for the widget module."""
16+
1517
from fire import testutils
1618

17-
from fire.examples.widget import widget
19+
from examples.widget import widget
1820

1921

2022
class WidgetTest(testutils.BaseTestCase):

fire/decorators_test.py

+39-34
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from fire import testutils
2424

2525

26-
class A(object):
26+
class NoDefaults(object):
2727

2828
@decorators.SetParseFns(count=int)
2929
def double(self, count):
@@ -43,7 +43,7 @@ def double(count):
4343
return 2 * count
4444

4545

46-
class B(object):
46+
class WithDefaults(object):
4747

4848
@decorators.SetParseFns(float)
4949
def example1(self, arg1=10):
@@ -54,14 +54,14 @@ def example2(self, arg1=10):
5454
return arg1, type(arg1)
5555

5656

57-
class C(object):
57+
class MixedArguments(object):
5858

5959
@decorators.SetParseFns(float, arg2=str)
6060
def example3(self, arg1, arg2):
6161
return arg1, arg2
6262

6363

64-
class D(object):
64+
class PartialParseFn(object):
6565

6666
@decorators.SetParseFns(arg1=str)
6767
def example4(self, arg1, arg2):
@@ -72,7 +72,7 @@ def example5(self, arg1, arg2):
7272
return arg1, arg2
7373

7474

75-
class E(object):
75+
class WithKwargs(object):
7676

7777
@decorators.SetParseFns(mode=str, count=int)
7878
def example6(self, **kwargs):
@@ -82,7 +82,7 @@ def example6(self, **kwargs):
8282
)
8383

8484

85-
class F(object):
85+
class WithVarArgs(object):
8686

8787
@decorators.SetParseFn(str)
8888
def example7(self, arg1, arg2=None, *varargs, **kwargs):
@@ -92,59 +92,64 @@ def example7(self, arg1, arg2=None, *varargs, **kwargs):
9292
class FireDecoratorsTest(testutils.BaseTestCase):
9393

9494
def testSetParseFnsNamedArgs(self):
95-
self.assertEqual(core.Fire(A, 'double 2'), 4)
96-
self.assertEqual(core.Fire(A, 'triple 4'), 12.0)
95+
self.assertEqual(core.Fire(NoDefaults, 'double 2'), 4)
96+
self.assertEqual(core.Fire(NoDefaults, 'triple 4'), 12.0)
9797

9898
def testSetParseFnsPositionalArgs(self):
99-
self.assertEqual(core.Fire(A, 'quadruple 5'), 20)
99+
self.assertEqual(core.Fire(NoDefaults, 'quadruple 5'), 20)
100100

101101
def testSetParseFnsFnWithPositionalArgs(self):
102102
self.assertEqual(core.Fire(double, '5'), 10)
103103

104104
def testSetParseFnsDefaultsFromPython(self):
105105
# When called from Python, function should behave normally.
106-
self.assertTupleEqual(B().example1(), (10, int))
107-
self.assertEqual(B().example1(5), (5, int))
108-
self.assertEqual(B().example1(12.0), (12, float))
106+
self.assertTupleEqual(WithDefaults().example1(), (10, int))
107+
self.assertEqual(WithDefaults().example1(5), (5, int))
108+
self.assertEqual(WithDefaults().example1(12.0), (12, float))
109109

110110
def testSetParseFnsDefaultsFromFire(self):
111111
# Fire should use the decorator to know how to parse string arguments.
112-
self.assertEqual(core.Fire(B, 'example1'), (10, int))
113-
self.assertEqual(core.Fire(B, 'example1 10'), (10, float))
114-
self.assertEqual(core.Fire(B, 'example1 13'), (13, float))
115-
self.assertEqual(core.Fire(B, 'example1 14.0'), (14, float))
112+
self.assertEqual(core.Fire(WithDefaults, 'example1'), (10, int))
113+
self.assertEqual(core.Fire(WithDefaults, 'example1 10'), (10, float))
114+
self.assertEqual(core.Fire(WithDefaults, 'example1 13'), (13, float))
115+
self.assertEqual(core.Fire(WithDefaults, 'example1 14.0'), (14, float))
116116

117117
def testSetParseFnsNamedDefaultsFromPython(self):
118118
# When called from Python, function should behave normally.
119-
self.assertTupleEqual(B().example2(), (10, int))
120-
self.assertEqual(B().example2(5), (5, int))
121-
self.assertEqual(B().example2(12.0), (12, float))
119+
self.assertTupleEqual(WithDefaults().example2(), (10, int))
120+
self.assertEqual(WithDefaults().example2(5), (5, int))
121+
self.assertEqual(WithDefaults().example2(12.0), (12, float))
122122

123123
def testSetParseFnsNamedDefaultsFromFire(self):
124124
# Fire should use the decorator to know how to parse string arguments.
125-
self.assertEqual(core.Fire(B, 'example2'), (10, int))
126-
self.assertEqual(core.Fire(B, 'example2 10'), (10, float))
127-
self.assertEqual(core.Fire(B, 'example2 13'), (13, float))
128-
self.assertEqual(core.Fire(B, 'example2 14.0'), (14, float))
125+
self.assertEqual(core.Fire(WithDefaults, 'example2'), (10, int))
126+
self.assertEqual(core.Fire(WithDefaults, 'example2 10'), (10, float))
127+
self.assertEqual(core.Fire(WithDefaults, 'example2 13'), (13, float))
128+
self.assertEqual(core.Fire(WithDefaults, 'example2 14.0'), (14, float))
129129

130130
def testSetParseFnsPositionalAndNamed(self):
131-
self.assertEqual(core.Fire(C, 'example3 10 10'), (10, '10'))
131+
self.assertEqual(core.Fire(MixedArguments, 'example3 10 10'), (10, '10'))
132132

133133
def testSetParseFnsOnlySomeTypes(self):
134-
self.assertEqual(core.Fire(D, 'example4 10 10'), ('10', 10))
135-
self.assertEqual(core.Fire(D, 'example5 10 10'), (10, '10'))
134+
self.assertEqual(core.Fire(PartialParseFn, 'example4 10 10'), ('10', 10))
135+
self.assertEqual(core.Fire(PartialParseFn, 'example5 10 10'), (10, '10'))
136136

137137
def testSetParseFnsForKeywordArgs(self):
138-
self.assertEqual(core.Fire(E, 'example6'), ('default', 0))
139-
self.assertEqual(core.Fire(E, 'example6 --herring "red"'), ('default', 0))
140-
self.assertEqual(core.Fire(E, 'example6 --mode train'), ('train', 0))
141-
self.assertEqual(core.Fire(E, 'example6 --mode 3'), ('3', 0))
142-
self.assertEqual(core.Fire(E, 'example6 --mode -1 --count 10'), ('-1', 10))
143-
self.assertEqual(core.Fire(E, 'example6 --count -2'), ('default', -2))
138+
self.assertEqual(core.Fire(WithKwargs, 'example6'), ('default', 0))
139+
self.assertEqual(
140+
core.Fire(WithKwargs, 'example6 --herring "red"'), ('default', 0))
141+
self.assertEqual(
142+
core.Fire(WithKwargs, 'example6 --mode train'), ('train', 0))
143+
self.assertEqual(core.Fire(WithKwargs, 'example6 --mode 3'), ('3', 0))
144+
self.assertEqual(
145+
core.Fire(WithKwargs, 'example6 --mode -1 --count 10'), ('-1', 10))
146+
self.assertEqual(
147+
core.Fire(WithKwargs, 'example6 --count -2'), ('default', -2))
144148

145149
def testSetParseFn(self):
146-
self.assertEqual(core.Fire(F, 'example7 1 --arg2=2 3 4 --kwarg=5'),
147-
('1', '2', ('3', '4'), {'kwarg': '5'}))
150+
self.assertEqual(
151+
core.Fire(WithVarArgs, 'example7 1 --arg2=2 3 4 --kwarg=5'),
152+
('1', '2', ('3', '4'), {'kwarg': '5'}))
148153

149154

150155
if __name__ == '__main__':

fire/inspectutils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def GetFullArgSpec(fn):
9494
annotations = getattr(fn, '__annotations__', None)
9595
else:
9696
(args, varargs, varkw, defaults,
97-
kwonlyargs, kwonlydefaults, annotations) = inspect.getfullargspec(fn) # pylint: disable=no-member
97+
kwonlyargs, kwonlydefaults, annotations) = inspect.getfullargspec(fn) # pylint: disable=deprecated-method,no-member
9898

9999
except TypeError:
100100
# If we can't get the argspec, how do we know if the fn should take args?

fire/test_components.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import six
2222

2323
if six.PY3:
24-
from fire import test_components_py3 as py3 # pylint: disable=unused-import
24+
from fire import test_components_py3 as py3 # pylint: disable=unused-import,no-name-in-module
2525

2626

2727
def identity(arg1, arg2, arg3=10, arg4=20, *arg5, **arg6):

pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class-rgx=[A-Z_][a-zA-Z0-9]+$
9595
function-rgx=^(?:(?P<camel_case>_?[A-Z][a-zA-Z0-9]*)|(?P<snake_case>_?[a-z][a-z0-9_]*))$
9696

9797
# Regular expression which should only match correct method names
98-
method-rgx=^(?:(?P<exempt>__[a-z0-9_]+__|next)|(?P<camel_case>_{0,2}(test)?[A-Z][a-zA-Z0-9]*)|(?P<snake_case>_{0,2}[a-z][a-z0-9_]*))$
98+
method-rgx=^(?:(?P<exempt>__[a-z0-9_]+__|next)|(?P<camel_case>_{0,2}(?:test|assert)?[A-Z][a-zA-Z0-9]*)|(?:_{0,2}[a-z][a-z0-9_]*))$
9999

100100
# Regular expression which should only match correct instance attribute names
101101
attr-rgx=^_{0,2}[a-z][a-z0-9_]*$

setup.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[aliases]
2+
test=pytest
3+
4+
[tool:pytest]
5+
addopts = --ignore=fire/test_components_py3.py --ignore=fire/parser_fuzz_test.py

setup.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
from setuptools import setup
1818

19-
long_description = """
19+
20+
LONG_DESCRIPTION = """
2021
Python Fire is a library for automatically generating command line interfaces
2122
(CLIs) with a single line of code.
2223
@@ -25,15 +26,15 @@
2526
it fires off your command.
2627
""".strip()
2728

28-
short_description = """
29+
SHORT_DESCRIPTION = """
2930
A library for automatically generating commane line interfaces.""".strip()
3031

31-
dependencies = [
32+
DEPENDENCIES = [
3233
'ipython',
3334
'six',
3435
]
3536

36-
test_dependencies = [
37+
TEST_DEPENDENCIES = [
3738
'hypothesis',
3839
'mock',
3940
'python-Levenshtein',
@@ -43,8 +44,8 @@
4344
name='fire',
4445
version='0.1.0',
4546

46-
description=short_description,
47-
long_description=long_description,
47+
description=SHORT_DESCRIPTION,
48+
long_description=LONG_DESCRIPTION,
4849

4950
url='https://github.com/google/python-fire',
5051

@@ -79,6 +80,6 @@
7980

8081
packages=['fire'],
8182

82-
install_requires=dependencies,
83-
tests_require=test_dependencies,
83+
install_requires=DEPENDENCIES,
84+
tests_require=TEST_DEPENDENCIES,
8485
)

0 commit comments

Comments
 (0)