Skip to content

Commit 4198d5a

Browse files
authored
Adds pylintrc and moves towards conforming to the pylintrc (google#36)
* Adds pylintrc and moves towards conforming to that pylintrc. * Also moves all tests to use testutils.BaseTestCase. Copybara generated commit for Python Fire. PiperOrigin-RevId: 151341797 Change-Id: I1c4d7ecf1fc4d7931e6c91328649fa5da9e916e1 Reviewed-on: https://team-review.git.corp.google.com/65525 Reviewed-by: David Bieber <[email protected]>
1 parent 05d5933 commit 4198d5a

22 files changed

+322
-69
lines changed

examples/cipher/cipher_test.py

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

15-
from fire.examples.cipher import cipher
15+
from fire import testutils
1616

17-
import unittest
17+
from fire.examples.cipher import cipher
1818

1919

20-
class CipherTest(unittest.TestCase):
20+
class CipherTest(testutils.BaseTestCase):
2121

2222
def testCipher(self):
2323
self.assertEqual(cipher.rot13('Hello world!'), 'Uryyb jbeyq!')
@@ -29,4 +29,4 @@ def testCipher(self):
2929

3030

3131
if __name__ == '__main__':
32-
unittest.main()
32+
testutils.main()

examples/diff/diff_test.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
import tempfile
1616

17+
from fire import testutils
18+
1719
from fire.examples.diff import diff
1820
from fire.examples.diff import difffull
1921

20-
import unittest
21-
2222

23-
class DiffTest(unittest.TestCase):
23+
class DiffTest(testutils.BaseTestCase):
2424
"""The purpose of these tests is to ensure the difflib wrappers works.
2525
2626
It is not the goal of these tests to exhaustively test difflib functionality.
@@ -90,4 +90,4 @@ def testDiffFull(self):
9090

9191

9292
if __name__ == '__main__':
93-
unittest.main()
93+
testutils.main()

examples/widget/collector_test.py

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

15+
from fire import testutils
16+
1517
from fire.examples.widget import collector
1618
from fire.examples.widget import widget
1719

18-
import unittest
19-
2020

21-
class CollectorTest(unittest.TestCase):
21+
class CollectorTest(testutils.BaseTestCase):
2222

2323
def testCollectorHasWidget(self):
2424
col = collector.Collector()
@@ -34,4 +34,4 @@ def testCollectorGetsWantedWidgets(self):
3434

3535

3636
if __name__ == '__main__':
37-
unittest.main()
37+
testutils.main()

examples/widget/widget_test.py

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

15-
from fire.examples.widget import widget
15+
from fire import testutils
1616

17-
import unittest
17+
from fire.examples.widget import widget
1818

1919

20-
class WidgetTest(unittest.TestCase):
20+
class WidgetTest(testutils.BaseTestCase):
2121

2222
def testWidgetWhack(self):
2323
toy = widget.Widget()
@@ -31,4 +31,4 @@ def testWidgetBang(self):
3131

3232

3333
if __name__ == '__main__':
34-
unittest.main()
34+
testutils.main()

fire/completion.py

-1
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,3 @@ def _Commands(component, depth=3):
226226

227227
for command in _Commands(member, depth - 1):
228228
yield (member_name,) + command
229-

fire/completion_test.py

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

15+
"""Tests for the completion module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
1820

1921
from fire import completion
2022
from fire import test_components as tc
21-
22-
import unittest
23+
from fire import testutils
2324

2425

25-
class TabCompletionTest(unittest.TestCase):
26+
class TabCompletionTest(testutils.BaseTestCase):
2627

2728
def testCompletionScript(self):
2829
# A sanity check test to make sure the completion script satisfies some
@@ -32,7 +33,7 @@ def testCompletionScript(self):
3233
['halt'],
3334
['halt', '--now'],
3435
]
35-
script = completion._Script(name='command', commands=commands)
36+
script = completion._Script(name='command', commands=commands) # pylint: disable=protected-access
3637
self.assertIn('command', script)
3738
self.assertIn('halt', script)
3839
self.assertIn('"$start" == "command"', script)
@@ -135,4 +136,4 @@ def testMethodCompletions(self):
135136

136137

137138
if __name__ == '__main__':
138-
unittest.main()
139+
testutils.main()

fire/core_test.py

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

15+
"""Tests for the core module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
@@ -22,16 +24,14 @@
2224
from fire import trace
2325
import mock
2426

25-
import unittest
26-
2727

2828
class CoreTest(testutils.BaseTestCase):
2929

3030
def testOneLineResult(self):
31-
self.assertEqual(core._OneLineResult(1), '1')
32-
self.assertEqual(core._OneLineResult('hello'), 'hello')
33-
self.assertEqual(core._OneLineResult({}), '{}')
34-
self.assertEqual(core._OneLineResult({'x': 'y'}), '{"x": "y"}')
31+
self.assertEqual(core._OneLineResult(1), '1') # pylint: disable=protected-access
32+
self.assertEqual(core._OneLineResult('hello'), 'hello') # pylint: disable=protected-access
33+
self.assertEqual(core._OneLineResult({}), '{}') # pylint: disable=protected-access
34+
self.assertEqual(core._OneLineResult({'x': 'y'}), '{"x": "y"}') # pylint: disable=protected-access
3535

3636
@mock.patch('fire.interact.Embed')
3737
def testInteractiveMode(self, mock_embed):
@@ -94,4 +94,4 @@ def testFireErrorMultipleValues(self):
9494
self.assertIsNotNone(error)
9595

9696
if __name__ == '__main__':
97-
unittest.main()
97+
testutils.main()

fire/decorators_test.py

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

15+
"""Tests for the decorators module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
1820

1921
from fire import core
2022
from fire import decorators
21-
22-
import unittest
23+
from fire import testutils
2324

2425

2526
class A(object):
@@ -88,7 +89,7 @@ def example7(self, arg1, arg2=None, *varargs, **kwargs):
8889
return arg1, arg2, varargs, kwargs
8990

9091

91-
class FireDecoratorsTest(unittest.TestCase):
92+
class FireDecoratorsTest(testutils.BaseTestCase):
9293

9394
def testSetParseFnsNamedArgs(self):
9495
self.assertEqual(core.Fire(A, 'double 2'), 4)
@@ -147,4 +148,4 @@ def testSetParseFn(self):
147148

148149

149150
if __name__ == '__main__':
150-
unittest.main()
151+
testutils.main()

fire/fire_import_test.py

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

15-
import mock
15+
"""Tests importing the fire module."""
16+
1617
import sys
17-
import unittest
1818

1919
import fire
20+
from fire import testutils
21+
import mock
2022

2123

22-
class FireImportTest(unittest.TestCase):
24+
class FireImportTest(testutils.BaseTestCase):
2325
"""Tests importing Fire."""
2426

2527
def testFire(self):
@@ -35,4 +37,4 @@ def testNoPrivateMethods(self):
3537

3638

3739
if __name__ == '__main__':
38-
unittest.main()
40+
testutils.main()

fire/fire_test.py

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

15+
"""Tests for the fire module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
@@ -414,4 +416,4 @@ def testTraceErrors(self):
414416

415417

416418
if __name__ == '__main__':
417-
unittest.main()
419+
testutils.main()

fire/helputils_test.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""Tests for the helputils module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
1820

21+
import os
22+
1923
from fire import helputils
2024
from fire import test_components as tc
25+
from fire import testutils
2126
import six
2227

23-
import unittest
24-
import os
25-
2628

27-
class HelpUtilsTest(unittest.TestCase):
29+
class HelpUtilsTest(testutils.BaseTestCase):
2830

2931
def testHelpStringClass(self):
3032
helpstring = helputils.HelpString(tc.NoDefaults)
@@ -126,4 +128,4 @@ def testHelpClassNoInit(self):
126128

127129

128130
if __name__ == '__main__':
129-
unittest.main()
131+
testutils.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)
97+
kwonlyargs, kwonlydefaults, annotations) = inspect.getfullargspec(fn) # pylint: disable=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/inspectutils_test.py

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

15+
"""Tests for the inspectutils module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
@@ -21,11 +23,12 @@
2123

2224
from fire import inspectutils
2325
from fire import test_components as tc
26+
from fire import testutils
2427

2528
import six
2629

2730

28-
class InspectUtilsTest(unittest.TestCase):
31+
class InspectUtilsTest(testutils.BaseTestCase):
2932

3033
def testGetFullArgSpec(self):
3134
spec = inspectutils.GetFullArgSpec(tc.identity)
@@ -113,4 +116,4 @@ def testInfoClassNoInit(self):
113116

114117

115118
if __name__ == '__main__':
116-
unittest.main()
119+
testutils.main()

fire/interact_test.py

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

15+
"""Tests for the interact module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
1820

1921
from fire import interact
20-
import mock
22+
from fire import testutils
2123

22-
import unittest
24+
import mock
2325

2426

25-
class InteractTest(unittest.TestCase):
27+
class InteractTest(testutils.BaseTestCase):
2628

2729
@mock.patch('IPython.start_ipython')
2830
def testInteract(self, mock_ipython):
@@ -40,4 +42,4 @@ def testInteractVariables(self, mock_ipython):
4042
self.assertTrue(mock_ipython.called)
4143

4244
if __name__ == '__main__':
43-
unittest.main()
45+
testutils.main()

fire/parser_fuzz_test.py

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

15+
"""Fuzz tests for the parser module."""
16+
1517
from __future__ import absolute_import
1618
from __future__ import division
1719
from __future__ import print_function
1820

1921
from fire import parser
22+
from fire import testutils
2023
from hypothesis import example
2124
from hypothesis import given
2225
from hypothesis import settings
2326
from hypothesis import strategies as st
2427
import Levenshtein
2528
import six
2629

27-
import unittest
28-
2930

30-
class ParserFuzzTest(unittest.TestCase):
31+
class ParserFuzzTest(testutils.BaseTestCase):
3132

3233
@given(st.text(min_size=1), settings=settings.Settings(max_examples=10000))
3334
@example('True')
@@ -94,4 +95,4 @@ def testDefaultParseValueFuzz(self, value):
9495

9596

9697
if __name__ == '__main__':
97-
unittest.main()
98+
testutils.main()

0 commit comments

Comments
 (0)