Skip to content

Commit e6419b3

Browse files
committed
Added 1 module, 1 class, 3 constants, 31 functions, and 5 kwargs
1 parent 025b4e4 commit e6419b3

File tree

7 files changed

+198
-1
lines changed

7 files changed

+198
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Everything is contained within "minpy.py" - no other file is necessary.
77

88
Since the code is vanilla Python, and it doesn't have any external dependencies, it works with v2.7+ and v3+.
99

10-
It functions by parsing Python code into an abstract syntax tree (AST), which it traverses and matches against internal dictionaries of 39 modules, 88 classes/functions/constants members of modules, and 16 kwargs of functions. Including looking for v2/v3 `print expr` and `print(expr)`, `"..".format(..)`, imports (`import X`, `from X import Y`, `from X import *`), and function calls wrt. name and kwargs.
10+
It functions by parsing Python code into an abstract syntax tree (AST), which it traverses and matches against internal dictionaries with 184 rules divided into 40 modules, 123 classes/functions/constants members of modules, and 21 kwargs of functions. Including looking for v2/v3 `print expr` and `print(expr)`, `"..".format(..)`, imports (`import X`, `from X import Y`, `from X import *`), and function calls wrt. name and kwargs.
1111

1212
## Usage
1313
It is fairly straightforward to use Minpy:
@@ -30,6 +30,7 @@ Options:
3030
-v.. Verbosity level 1 to 2. -v shows less than -vv but more than no verbosity.
3131
-i Ignore incompatible version warnings.
3232
-p=X Use X concurrent processes to analyze files (defaults to all cores = 8).
33+
-d Dump AST node visits.
3334
3435
% ./minpy.py -q minpy.py
3536
Minimum required versions: 2.7, 3.0

class_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ def test_terminal_size_of_os(self):
1212

1313
def test_Barrier_of_multiprocessing(self):
1414
self.assertOnlyIn(3.3, detect("from multiprocessing import Barrier"))
15+
16+
def test_TextTestResult_of_unittest(self):
17+
self.assertOnlyIn((2.7, 3.0), detect("from unittest import TextTestResult"))

constants_tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,15 @@ def test_version_info_of_sys(self):
9393

9494
def test_sentinel_of_multiprocessing_Process(self):
9595
self.assertOnlyIn(3.3, detect("from multiprocessing import Process\np = Process()\np.sentinel"))
96+
97+
def test_skipped_of_unittest_TestResult(self):
98+
self.assertOnlyIn((2.7, 3.0),
99+
detect("from unittest import TestResult\np = TestResult()\np.skipped"))
100+
101+
def test_buffer_of_unittest_TestResult(self):
102+
self.assertOnlyIn((2.7, 3.0),
103+
detect("from unittest import TestResult\np = TestResult()\np.buffer"))
104+
105+
def test_failfast_of_unittest_TestResult(self):
106+
self.assertOnlyIn((2.7, 3.0),
107+
detect("from unittest import TestResult\np = TestResult()\np.failfast"))

function_tests.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,122 @@ def test_set_start_method_of_multiprocessing(self):
164164

165165
def test_get_context_of_multiprocessing(self):
166166
self.assertOnlyIn(3.4, detect("import multiprocessing\nget_context()"))
167+
168+
def test_assertIs_of_unittest_TestCase(self):
169+
self.assertOnlyIn((2.7, 3.0), detect("from unittest import TestCase\nTestCase.assertIs()"))
170+
171+
def test_assertIsNot_of_unittest_TestCase(self):
172+
self.assertOnlyIn((2.7, 3.0), detect("from unittest import TestCase\nTestCase.assertIsNot()"))
173+
174+
def test_assertIsNone_of_unittest_TestCase(self):
175+
self.assertOnlyIn((2.7, 3.0), detect("from unittest import TestCase\nTestCase.assertIsNone()"))
176+
177+
def test_assertIsNotNone_of_unittest_TestCase(self):
178+
self.assertOnlyIn((2.7, 3.0),
179+
detect("from unittest import TestCase\nTestCase.assertIsNotNone()"))
180+
181+
def test_assertIn_of_unittest_TestCase(self):
182+
self.assertOnlyIn((2.7, 3.0), detect("from unittest import TestCase\nTestCase.assertIn()"))
183+
184+
def test_assertNotIn_of_unittest_TestCase(self):
185+
self.assertOnlyIn((2.7, 3.0), detect("from unittest import TestCase\nTestCase.assertNotIn()"))
186+
187+
def test_assertIsInstance_of_unittest_TestCase(self):
188+
self.assertOnlyIn((2.7, 3.0),
189+
detect("from unittest import TestCase\nTestCase.assertIsInstance()"))
190+
191+
def test_assertNotIsInstance_of_unittest_TestCase(self):
192+
self.assertOnlyIn((2.7, 3.0),
193+
detect("from unittest import TestCase\nTestCase.assertNotIsInstance()"))
194+
195+
def test_assertRaisesRegexp_of_unittest_TestCase(self):
196+
self.assertOnlyIn((2.7, 3.0),
197+
detect("from unittest import TestCase\nTestCase.assertRaisesRegexp()"))
198+
199+
def test_assertGreater_of_unittest_TestCase(self):
200+
self.assertOnlyIn((2.7, 3.0),
201+
detect("from unittest import TestCase\nTestCase.assertGreater()"))
202+
203+
def test_assertGreaterEqual_of_unittest_TestCase(self):
204+
self.assertOnlyIn((2.7, 3.0),
205+
detect("from unittest import TestCase\nTestCase.assertGreaterEqual()"))
206+
207+
def test_assertLess_of_unittest_TestCase(self):
208+
self.assertOnlyIn((2.7, 3.0),
209+
detect("from unittest import TestCase\nTestCase.assertLess()"))
210+
211+
def test_assertLessEqual_of_unittest_TestCase(self):
212+
self.assertOnlyIn((2.7, 3.0),
213+
detect("from unittest import TestCase\nTestCase.assertLessEqual()"))
214+
215+
def test_assertRegexpMatches_of_unittest_TestCase(self):
216+
self.assertOnlyIn((2.7, 3.0),
217+
detect("from unittest import TestCase\nTestCase.assertRegexpMatches()"))
218+
219+
def test_assertNotRegexpMatches_of_unittest_TestCase(self):
220+
self.assertOnlyIn((2.7, 3.0),
221+
detect("from unittest import TestCase\nTestCase.assertNotRegexpMatches()"))
222+
223+
def test_assertItemsEqual_of_unittest_TestCase(self):
224+
self.assertOnlyIn((2.7, 3.0),
225+
detect("from unittest import TestCase\nTestCase.assertItemsEqual()"))
226+
227+
def test_assertDictContainsSubset_of_unittest_TestCase(self):
228+
self.assertOnlyIn((2.7, 3.0),
229+
detect("from unittest import TestCase\nTestCase.assertDictContainsSubset()"))
230+
231+
def test_addTypeEqualityFunc_of_unittest_TestCase(self):
232+
self.assertOnlyIn((2.7, 3.0),
233+
detect("from unittest import TestCase\nTestCase.addTypeEqualityFunc()"))
234+
235+
def test_assertMultilineEqual_of_unittest_TestCase(self):
236+
self.assertOnlyIn((2.7, 3.0),
237+
detect("from unittest import TestCase\nTestCase.assertMultilineEqual()"))
238+
239+
def test_assertSequenceEqual_of_unittest_TestCase(self):
240+
self.assertOnlyIn((2.7, 3.0),
241+
detect("from unittest import TestCase\nTestCase.assertSequenceEqual()"))
242+
243+
def test_assertListEqual_of_unittest_TestCase(self):
244+
self.assertOnlyIn((2.7, 3.0),
245+
detect("from unittest import TestCase\nTestCase.assertListEqual()"))
246+
247+
def test_assertTupleEqual_of_unittest_TestCase(self):
248+
self.assertOnlyIn((2.7, 3.0),
249+
detect("from unittest import TestCase\nTestCase.assertTupleEqual()"))
250+
251+
def test_assertSetEqual_of_unittest_TestCase(self):
252+
self.assertOnlyIn((2.7, 3.0),
253+
detect("from unittest import TestCase\nTestCase.assertSetEqual()"))
254+
255+
def test_assertDictEqual_of_unittest_TestCase(self):
256+
self.assertOnlyIn((2.7, 3.0),
257+
detect("from unittest import TestCase\nTestCase.assertDictEqual()"))
258+
259+
def test_longMessage_of_unittest_TestCase(self):
260+
self.assertOnlyIn((2.7, 3.0),
261+
detect("from unittest import TestCase\nTestCase.longMessage()"))
262+
263+
def test_maxDiff_of_unittest_TestCase(self):
264+
self.assertOnlyIn((2.7, 3.0),
265+
detect("from unittest import TestCase\nTestCase.maxDiff()"))
266+
267+
def test_addCleanup_of_unittest_TestCase(self):
268+
self.assertOnlyIn((2.7, 3.0),
269+
detect("from unittest import TestCase\nTestCase.addCleanup()"))
270+
271+
def test_doCleanup_of_unittest_TestCase(self):
272+
self.assertOnlyIn((2.7, 3.0),
273+
detect("from unittest import TestCase\nTestCase.doCleanup()"))
274+
275+
def test_discover_of_unittest_TestLoader(self):
276+
self.assertOnlyIn((2.7, 3.0),
277+
detect("from unittest import TestLoader\nTestLoader.discover()"))
278+
279+
def test_startTestRun_of_unittest_TestResult(self):
280+
self.assertOnlyIn((2.7, 3.0),
281+
detect("from unittest import TestResult\nTestResult.startTestRun()"))
282+
283+
def test_stopTestRun_of_unittest_TestResult(self):
284+
self.assertOnlyIn((2.7, 3.0),
285+
detect("from unittest import TestResult\nTestResult.stopTestRun()"))

kwargs_tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,21 @@ def test_context_of_Pool_from_multiprocessing(self):
4949

5050
def test_daemon_of_Process_from_multiprocessing(self):
5151
self.assertOnlyIn(3.3, detect("import multiprocessing\nProcess(daemon=None)"))
52+
53+
def test_compact_of_PrettyPrinter_from_pprint(self):
54+
self.assertOnlyIn(3.4, detect("import pprint\npprint.PrettyPrinter(compact=True)"))
55+
56+
def test_compact_of_pformat_from_pprint(self):
57+
self.assertOnlyIn(3.4, detect("import pprint\npprint.pformat(compact=True)"))
58+
59+
def test_compact_of_pprint_from_pprint(self):
60+
self.assertOnlyIn(3.4, detect("import pprint\npprint.pprint(compact=True)"))
61+
62+
def test_delta_of_assertAlmostEqual_from_unitest_TestCase(self):
63+
self.assertOnlyIn((2.7, 3.0),
64+
detect("from unittest import TestCase\nTestCase.assertAlmostEqual(delta=1)"))
65+
66+
def test_delta_of_assertNotAlmostEqual_from_unitest_TestCase(self):
67+
self.assertOnlyIn((2.7, 3.0),
68+
detect("from unittest import TestCase\n"
69+
"TestCase.assertNotAlmostEqual(delta=1)"))

minpy.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"string.lowercase": (2.0, None),
4545
"string.uppercase": (2.0, None),
4646
"tkinter": (None, 3.0),
47+
"unittest": (2.1, 3.0),
4748
"urllib2": (2.0, None),
4849
"winreg": (None, 3.0),
4950
"xmlrpc": (None, 3.0),
@@ -55,10 +56,38 @@
5556
"ABC": ("abc", (None, 3.4)),
5657
"Barrier": ("multiprocessing", (None, 3.3)),
5758
"PathLike": ("os", (None, 3.6)),
59+
"TextTestResult": ("unittest", (2.7, 3.0)),
5860
"terminal_size": ("os", (None, 3.3)),
5961

6062
# Functions
63+
"addCleanup": ("unittest.TestCase", (2.7, 3.0)),
64+
"addTypeEqualityFunc": ("unittest.TestCase", (2.7, 3.0)),
65+
"assertDictContainsSubset": ("unittest.TestCase", (2.7, 3.0)),
66+
"assertDictEqual": ("unittest.TestCase", (2.7, 3.0)),
67+
"assertGreater": ("unittest.TestCase", (2.7, 3.0)),
68+
"assertGreaterEqual": ("unittest.TestCase", (2.7, 3.0)),
69+
"assertIn": ("unittest.TestCase", (2.7, 3.0)),
70+
"assertIs": ("unittest.TestCase", (2.7, 3.0)),
71+
"assertIsInstance": ("unittest.TestCase", (2.7, 3.0)),
72+
"assertIsNone": ("unittest.TestCase", (2.7, 3.0)),
73+
"assertIsNot": ("unittest.TestCase", (2.7, 3.0)),
74+
"assertIsNotNone": ("unittest.TestCase", (2.7, 3.0)),
75+
"assertItemsEqual": ("unittest.TestCase", (2.7, 3.0)),
76+
"assertLess": ("unittest.TestCase", (2.7, 3.0)),
77+
"assertLessEqual": ("unittest.TestCase", (2.7, 3.0)),
78+
"assertListEqual": ("unittest.TestCase", (2.7, 3.0)),
79+
"assertMultilineEqual": ("unittest.TestCase", (2.7, 3.0)),
80+
"assertNotIn": ("unittest.TestCase", (2.7, 3.0)),
81+
"assertNotIsInstance": ("unittest.TestCase", (2.7, 3.0)),
82+
"assertNotRegexpMatches": ("unittest.TestCase", (2.7, 3.0)),
83+
"assertRaisesRegexp": ("unittest.TestCase", (2.7, 3.0)),
84+
"assertRegexpMatches": ("unittest.TestCase", (2.7, 3.0)),
85+
"assertSequenceEqual": ("unittest.TestCase", (2.7, 3.0)),
86+
"assertSetEqual": ("unittest.TestCase", (2.7, 3.0)),
87+
"assertTupleEqual": ("unittest.TestCase", (2.7, 3.0)),
6188
"commonpath": ("os.path", (None, 3.5)),
89+
"discover": ("unittest.TestLoader", (2.7, 3.0)),
90+
"doCleanup": ("unittest.TestCase", (2.7, 3.0)),
6291
"exc_clear": ("sys", (2.3, None)),
6392
"fsdecode": ("os", (None, 3.2)),
6493
"fsencode": ("os", (None, 3.2)),
@@ -91,6 +120,8 @@
91120
"ismount": ("os.path", (None, 3.4)),
92121
"lexists": ("os.path", (2.4, 3.0)),
93122
"lockf": ("os", (None, 3.3)),
123+
"longMessage": ("unittest.TestCase", (2.7, 3.0)),
124+
"maxDiff": ("unittest.TestCase", (2.7, 3.0)),
94125
"pipe2": ("os", (None, 3.3)),
95126
"posix_fadvise": ("os", (None, 3.3)),
96127
"posix_fallocate": ("os", (None, 3.3)),
@@ -109,6 +140,8 @@
109140
"setresuid": ("os", (2.7, 3.2)),
110141
"starmap": ("multiprocessing.Pool", (None, 3.3)),
111142
"starmap_async": ("multiprocessing.Pool", (None, 3.3)),
143+
"startTestRun": ("unittest.TestResult", (2.7, 3.0)),
144+
"stopTestRun": ("unittest.TestResult", (2.7, 3.0)),
112145
"wait": ("multiprocessing.connection", (None, 3.3)),
113146
"writev": ("os", (None, 3.3)),
114147

@@ -133,13 +166,16 @@
133166
"SF_NODISKIO": ("os", (None, 3.3)),
134167
"SF_SYNC": ("os", (None, 3.3)),
135168
"api_version": ("sys", (2.3, 3.0)),
169+
"buffer": ("unittest.TestResult", (2.7, 3.0)),
136170
"environb": ("os", (None, 3.2)),
171+
"failfast": ("unittest.TestResult", (2.7, 3.0)),
137172
"flags": ("sys", (2.6, 3.0)),
138173
"float_info": ("sys", (2.6, 3.0)),
139174
"float_repr_style": ("sys", (2.7, 3.0)),
140175
"long_info": ("sys", (2.7, None)),
141176
"py3kwarning": ("sys", (2.6, None)),
142177
"sentinel": ("multiprocessing.Process", (None, 3.3)),
178+
"skipped": ("unittest.TestResult", (2.7, 3.0)),
143179
"subversion": ("sys", (2.5, None)),
144180
"supports_bytes_environ": ("os", (None, 3.2)),
145181
"supports_unicode_filenames": ("os.path", (2.3, 3.0)),
@@ -150,10 +186,13 @@
150186
KWARGS_REQS = {
151187
("Pool", "context"): (None, 3.4), # multiprocessing
152188
("Pool", "maxtasksperchild"): (None, 3.2), # multiprocessing
189+
("PrettyPrinter", "compact"): (None, 3.4), # pprint
153190
("Process", "daemon"): (None, 3.3), # multiprocessing
154191
("access", "dir_fd"): (None, 3.3), # os
155192
("access", "effective_ids"): (None, 3.3), # os
156193
("access", "follow_symlinks"): (None, 3.3), # os
194+
("assertAlmostEqual", "delta"): (2.7, 3.0), # unittest.TestCase
195+
("assertNotAlmostEqual", "delta"): (2.7, 3.0), # unittest.TestCase
157196
("chflags", "follow_symlinks"): (None, 3.3), # os
158197
("chmod", "dir_fd"): (None, 3.3), # os
159198
("chmod", "follow_symlinks"): (None, 3.3), # os
@@ -164,6 +203,8 @@
164203
("link", "follow_symlinks"): (None, 3.3), # os
165204
("link", "src_dir_fd"): (None, 3.3), # os
166205
("open", "dir_fd"): (None, 3.3), # os
206+
("pformat", "compact"): (None, 3.4), # pprint
207+
("pprint", "compact"): (None, 3.4), # pprint
167208
}
168209

169210
QUIET = False

module_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ def test_string_uppercase(self):
118118

119119
def test_ast(self):
120120
self.assertOnlyIn((2.6, 3.0), detect("import ast"))
121+
122+
def test_unittest(self):
123+
self.assertOnlyIn((2.1, 3.0), detect("import unittest"))

0 commit comments

Comments
 (0)