コード例 #1
0
 def test_b015(self):
     filename = Path(__file__).absolute().parent / "b015.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     expected = self.errors(B015(8, 0), B015(12, 0), B015(22, 4),
                            B015(29, 4))
     self.assertEqual(errors, expected)
コード例 #2
0
 def test_b011(self):
     filename = Path(__file__).absolute().parent / "b011.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B011(8, 0, vars=("i", )), B011(10, 0, vars=("k", ))))
コード例 #3
0
 def test_b013(self):
     filename = Path(__file__).absolute().parent / "b013.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     expected = self.errors(B013(10, 0, vars=("ValueError", )),
                            B013(28, 0, vars=("re.error", )))
     self.assertEqual(errors, expected)
コード例 #4
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b011(self):
     filename = Path(__file__).absolute().parent / 'b011.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B011(8, 0, vars=('i',)), B011(10, 0, vars=('k',))),
     )
コード例 #5
0
 def test_b004(self):
     filename = Path(__file__).absolute().parent / 'b004.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B004(3, 7), B004(5, 7)),
     )
コード例 #6
0
 def test_b950(self):
     filename = Path(__file__).absolute().parent / 'b950.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B950(6, 92, vars=(92, 79))),
     )
コード例 #7
0
 def test_b903(self):
     filename = Path(__file__).absolute().parent / 'b903.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B903(32, 0), B903(38, 0)),
     )
コード例 #8
0
 def test_b901(self):
     filename = Path(__file__).absolute().parent / 'b901.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B901(8, 8), B901(35, 4))
     )
コード例 #9
0
 def test_b306(self):
     filename = Path(__file__).absolute().parent / 'b306.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B306(9, 10)),
     )
コード例 #10
0
 def test_b006(self):
     filename = Path(__file__).absolute().parent / 'b006.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B006(8, 24), B006(12, 29), B006(16, 19), B006(20, 19)),
     )
コード例 #11
0
 def test_b007(self):
     filename = Path(__file__).absolute().parent / 'b007.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B007(6, 4, vars=('i',)), B007(18, 12, vars=('k',)),
                     B007(30, 4, vars=('i',)), B007(30, 12, vars=('k',))),
     )
コード例 #12
0
 def test_b005(self):
     filename = Path(__file__).absolute().parent / 'b005.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B005(4, 0), B005(7, 0), B005(10, 0), B005(13, 0),
                     B005(16, 0), B005(19, 0)),
     )
コード例 #13
0
 def test_b006_b008(self):
     filename = Path(__file__).absolute().parent / 'b006_b008.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B006(10, 24), B006(14, 29), B006(18, 19), B006(22, 19),
                     B006(25, 31), B008(32, 38)),
     )
コード例 #14
0
 def test_b301_b302_b305(self):
     filename = Path(__file__).absolute().parent / 'b301_b302_b305.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(B301(37, 4), B301(38, 4), B301(39, 4), B301(40, 4),
                     B302(41, 4), B302(42, 4), B302(43, 4), B302(44, 4),
                     B305(45, 4), B305(46, 4)),
     )
コード例 #15
0
 def test_b001(self):
     filename = Path(__file__).absolute().parent / "b001.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     expected = self.errors(
         B001(8, 0, vars=("bare `except:`", )),
         B001(40, 4, vars=("bare `except:`", )),
         B001(47, 0, vars=("`except ():`", )),
     )
     self.assertEqual(errors, expected)
コード例 #16
0
 def test_b014(self):
     filename = Path(__file__).absolute().parent / "b014.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     expected = self.errors(
         B014(10, 0, vars=("Exception, TypeError", "", "Exception")),
         B014(16, 0, vars=("OSError, OSError", " as err", "OSError")),
         B014(27, 0, vars=("MyError, MyError", "", "MyError")),
         B014(41, 0, vars=("MyError, BaseException", " as e", "BaseException")),
         B014(48, 0, vars=("re.error, re.error", "", "re.error")),
     )
     self.assertEqual(errors, expected)
コード例 #17
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b007(self):
     filename = Path(__file__).absolute().parent / "b007.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B007(6, 4, vars=("i",)),
             B007(18, 12, vars=("k",)),
             B007(30, 4, vars=("i",)),
             B007(30, 12, vars=("k",)),
         ),
     )
コード例 #18
0
 def test_b009_b010(self):
     filename = Path(__file__).absolute().parent / "b009_b010.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     all_errors = [
         B009(17, 0),
         B009(18, 0),
         B009(19, 0),
         B010(28, 0),
         B010(29, 0),
         B010(30, 0),
     ]
     self.assertEqual(errors, self.errors(*all_errors))
コード例 #19
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b005(self):
     filename = Path(__file__).absolute().parent / "b005.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B005(4, 0),
             B005(7, 0),
             B005(10, 0),
             B005(13, 0),
             B005(16, 0),
             B005(19, 0),
         ),
     )
コード例 #20
0
 def test_b006_b008(self):
     filename = Path(__file__).absolute().parent / "b006_b008.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B006(14, 24),
             B006(18, 29),
             B006(22, 19),
             B006(26, 19),
             B006(30, 31),
             B008(39, 38),
             B006(53, 32),
         ),
     )
コード例 #21
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b006_b008(self):
     filename = Path(__file__).absolute().parent / "b006_b008.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B006(14, 24),
             B006(18, 29),
             B006(22, 19),
             B006(26, 19),
             B006(30, 31),
             B008(39, 38),
             B006(53, 32),
         ),
     )
コード例 #22
0
 def test_b012(self):
     filename = Path(__file__).absolute().parent / "b012.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     all_errors = [
         B012(5, 8),
         B012(13, 12),
         B012(21, 12),
         B012(31, 12),
         B012(44, 20),
         B012(66, 12),
         B012(78, 12),
         B012(94, 12),
         B012(101, 8),
         B012(107, 8),
     ]
     self.assertEqual(errors, self.errors(*all_errors))
コード例 #23
0
 def test_b006_b008(self):
     filename = Path(__file__).absolute().parent / "b006_b008.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B006(26, 24),
             B006(30, 29),
             B006(34, 19),
             B006(38, 19),
             B006(42, 31),
             B008(51, 38),
             B006(67, 32),
             B008(95, 29),
             B008(99, 44),
         ),
     )
コード例 #24
0
 def test_does_not_crash_on_site_code(self):
     # Because the generator isn't perfect, we'll also test on all the code
     # we can easily find in our current Python environment - this includes
     # the standard library, and all installed packages.
     for base in sorted(set(site.PREFIXES)):
         for dirname, _, files in os.walk(base):
             for f in files:
                 if f.endswith(".py"):
                     BugBearChecker(filename=str(Path(dirname) / f))
コード例 #25
0
 def test_b006_b008(self):
     filename = Path(__file__).absolute().parent / "b006_b008.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B006(29, 24),
             B006(33, 29),
             B006(37, 19),
             B006(41, 19),
             B006(45, 31),
             B008(54, 38),
             B006(70, 32),
             B008(98, 29),
             B008(102, 44),
         ),
     )
コード例 #26
0
 def test_b902(self):
     filename = Path(__file__).absolute().parent / "b902.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B902(29, 17, vars=("'i_am_special'", "instance", "self")),
             B902(32, 30, vars=("'cls'", "instance", "self")),
             B902(35, 4, vars=("(none)", "instance", "self")),
             B902(39, 12, vars=("'self'", "class", "cls")),
             B902(42, 22, vars=("*args", "instance", "self")),
             B902(48, 30, vars=("**kwargs", "instance", "self")),
             B902(51, 32, vars=("*, self", "instance", "self")),
             B902(54, 44, vars=("*, self", "instance", "self")),
             B902(68, 17, vars=("'self'", "metaclass instance", "cls")),
             B902(72, 20, vars=("'cls'", "metaclass class", "metacls")),
         ),
     )
コード例 #27
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b902(self):
     filename = Path(__file__).absolute().parent / "b902.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B902(29, 17, vars=("'i_am_special'", "instance", "self")),
             B902(32, 30, vars=("'cls'", "instance", "self")),
             B902(35, 4, vars=("(none)", "instance", "self")),
             B902(39, 12, vars=("'self'", "class", "cls")),
             B902(42, 22, vars=("*args", "instance", "self")),
             B902(48, 30, vars=("**kwargs", "instance", "self")),
             B902(51, 32, vars=("*, self", "instance", "self")),
             B902(54, 44, vars=("*, self", "instance", "self")),
             B902(68, 17, vars=("'self'", "metaclass instance", "cls")),
             B902(72, 20, vars=("'cls'", "metaclass class", "metacls")),
         ),
     )
コード例 #28
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b301_b302_b305(self):
     filename = Path(__file__).absolute().parent / "b301_b302_b305.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B301(39, 4),
             B301(40, 4),
             B301(41, 4),
             B301(42, 4),
             B302(43, 4),
             B302(44, 4),
             B302(45, 4),
             B302(46, 4),
             B305(47, 4),
             B305(48, 4),
         ),
     )
コード例 #29
0
 def test_b902(self):
     filename = Path(__file__).absolute().parent / 'b902.py'
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(
         errors,
         self.errors(
             B902(26, 17, vars=("'i_am_special'", 'instance', 'self')),
             B902(29, 30, vars=("'cls'", 'instance', 'self')),
             B902(32, 4, vars=(
                 "(none)",
                 'instance',
                 'self',
             )),
             B902(36, 12, vars=("'self'", 'class', 'cls')),
             B902(39, 22, vars=("*args", 'instance', 'self')),
             B902(45, 30, vars=("**kwargs", 'instance', 'self')),
             B902(48, 32, vars=("*, self", 'instance', 'self')),
             B902(62, 17, vars=("'self'", 'metaclass instance', 'cls')),
             B902(66, 20, vars=("'cls'", 'metaclass class', 'metacls')),
         ))
コード例 #30
0
 def test_b003(self):
     filename = Path(__file__).absolute().parent / "b003.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(errors, self.errors(B003(10, 0)))
コード例 #31
0
 def errors(self, *errors):
     return [BugBearChecker.adapt_error(e) for e in errors]
コード例 #32
0
 def test_b303_b304(self):
     filename = Path(__file__).absolute().parent / "b303_b304.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(errors, self.errors(B303(25, 4), B304(42, 4)))
コード例 #33
0
 def test_b017(self):
     filename = Path(__file__).absolute().parent / "b017.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     expected = self.errors(B017(15, 8), B017(20, 8), B017(25, 8))
     self.assertEqual(errors, expected)
コード例 #34
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b009_b010(self):
     filename = Path(__file__).absolute().parent / "b009_b010.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(errors, self.errors(B009(15, 0), B010(22, 0)))
コード例 #35
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b004(self):
     filename = Path(__file__).absolute().parent / "b004.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(errors, self.errors(B004(3, 7), B004(5, 7)))
コード例 #36
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def errors(self, *errors):
     return [BugBearChecker.adapt_error(e) for e in errors]
コード例 #37
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b950(self):
     filename = Path(__file__).absolute().parent / "b950.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(errors, self.errors(B950(6, 92, vars=(92, 79))))
コード例 #38
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b903(self):
     filename = Path(__file__).absolute().parent / "b903.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(errors, self.errors(B903(32, 0), B903(38, 0)))
コード例 #39
0
ファイル: test_bugbear.py プロジェクト: ambv/flake8-bugbear
 def test_b306(self):
     filename = Path(__file__).absolute().parent / "b306.py"
     bbc = BugBearChecker(filename=str(filename))
     errors = list(bbc.run())
     self.assertEqual(errors, self.errors(B306(9, 10)))