def test_parse_format(self): for fmt in vermin.formats.names(): config = Config.parse_data(u"""[vermin] format = {} """.format(fmt)) self.assertIsNotNone(config) self.assertEqual(fmt, config.format().name()) self.assertIsNone(Config.parse_data(u"""[vermin] format = unknown """))
def __init__(self, methodName): super(VerminTest, self).__init__(methodName) # Allow test diffs of any size (instead of 640 char max). self.maxDiff = None # Append additional assertion message to the end of the normal failure message, instead of # replacing it. self.longMessage = True self.config = Config()
def test_parse_features(self): fs = Features.features() config = Config.parse_data(u"""[vermin] features = {} """.format("\n ".join(fs))) self.assertIsNotNone(config) self.assertEqual(fs, config.features()) self.assertIsNone(Config.parse_data(u"""[vermin] features = unknown """)) self.assertIsNone(Config.parse_data(u"""[vermin] features = {} unknown """.format(list(fs)[0])))
def test_detect_config_file_same_level(self): tmp_fld = mkdtemp() for candidate in CONFIG_FILE_NAMES: path = touch(tmp_fld, candidate, "[vermin]") self.assertEqual(path, Config.detect_config_file(tmp_fld)) os.remove(path) rmtree(tmp_fld)
def test_parse_backports(self): bps = Backports.modules() config = Config.parse_data(u"""[vermin] backports = {} """.format("\n ".join(bps))) self.assertIsNotNone(config) self.assertEqual(bps, config.backports()) config = Config.parse_data(u"""[vermin] backports = unknown """) self.assertIsNone(config) config = Config.parse_data(u"""[vermin] backports = {} unknown """.format(list(bps)[0])) self.assertIsNone(config)
def test_detect_config_file_two_level_depth(self): tmp_fld = mkdtemp() depth_fld = os.path.join(os.path.join(tmp_fld, "depth1"), "depth2") os.makedirs(depth_fld) for candidate in CONFIG_FILE_NAMES: path = touch(tmp_fld, candidate, "[vermin]") self.assertEqual(path, Config.detect_config_file(depth_fld)) os.remove(path) rmtree(tmp_fld)
def test_issue_68_override_from_add_exclusion(self): other = Config() self.config.override_from(other) # Calling `add_exclusion()` will call `set.add()` but `Config.__exclusions` has become a list # after `override_from()` and it would therefore crash. try: self.config.add_exclusion("x") except AttributeError: self.fail("Crashed while adding exclusion.")
def test_detect_config_file_project_boundary(self): tmp_fld = mkdtemp() depth1_fld = os.path.join(tmp_fld, "depth1") depth2_fld = os.path.join(depth1_fld, "depth2") os.makedirs(depth2_fld) # Create config at top level. touch(tmp_fld, CONFIG_FILE_NAMES[0], "[vermin]") # Create project boundary at depth one to stop further detection. for candidate in PROJECT_BOUNDARIES: boundary_fld = os.path.join(depth1_fld, candidate) os.makedirs(boundary_fld) self.assertIsNone(Config.detect_config_file(depth2_fld)) rmtree(boundary_fld) rmtree(tmp_fld)
def test_parse_file(self): fp = ScopedTemporaryFile() fp.write(b"""[vermin] quiet = 1 verbose = 2 print_visits = on ignore_incomp = yes lax = true pessimistic = TrUe """) fp.close() config = Config.parse_file(fp.path()) self.assertIsNotNone(config) self.assertTrue(config.quiet()) self.assertEqual(2, config.verbose()) self.assertTrue(config.print_visits()) self.assertTrue(config.ignore_incomp()) self.assertTrue(config.lax()) self.assertTrue(config.pessimistic())
def test_parse_targets(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.targets(), expected)
def test_parse_only_show_violations(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.only_show_violations(), expected)
def test_parse_scan_symlink_folders(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.scan_symlink_folders(), expected)
def test_parse_exclusions(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.exclusions(), expected)
#!/usr/bin/env python from vermin import Config, MOD_REQS, MOD_MEM_REQS, KWARGS_REQS, STRFTIME_REQS, BYTES_REQS,\ ARRAY_TYPECODE_REQS, CODECS_ERROR_HANDLERS, CODECS_ENCODINGS, BUILTIN_GENERIC_ANNOTATION_TYPES,\ DICT_UNION_SUPPORTED_TYPES, DICT_UNION_MERGE_SUPPORTED_TYPES, DECORATOR_USER_FUNCTIONS config = Config() (mods, mems, kwargs, dirs, bdirs, typecodes, codecshandlers, codecsencs, builtinanntypes, dictuniontypes, dictunionmergetypes, decouserfuncs) =\ (len(MOD_REQS(config)), len(MOD_MEM_REQS(config)), len(KWARGS_REQS), len(STRFTIME_REQS), len(BYTES_REQS), len(ARRAY_TYPECODE_REQS), len(CODECS_ERROR_HANDLERS), len(CODECS_ENCODINGS), len(BUILTIN_GENERIC_ANNOTATION_TYPES), len(DICT_UNION_SUPPORTED_TYPES), len(DICT_UNION_MERGE_SUPPORTED_TYPES), len(DECORATOR_USER_FUNCTIONS)) print( "Rules:\n{:>4} modules\n{:>4} members\n{:>4} kwargs\n{:>4} strftime directives\n{:>4} bytes " "format directives\n{:>4} array typecodes\n{:>4} codecs error handlers\n{:>4} codecs " "encodings\n{:>4} builtin generic annotation types\n{:>4} builtin dict union types\n{:>4} " "builtin dict union merge types\n{:>4} user function decorators\n{:>4} total" .format( mods, mems, kwargs, dirs, bdirs, typecodes, codecshandlers, codecsencs, builtinanntypes, dictuniontypes, dictunionmergetypes, decouserfuncs, mods + mems + kwargs + dirs + bdirs + typecodes + codecshandlers + codecsencs + builtinanntypes + dictuniontypes + dictunionmergetypes + decouserfuncs))
def __init__(self, methodName): super(VerminExclusionsTests, self).__init__(methodName) self.config = Config.get()
def __init__(self, methodName): super(VerminLaxModeTests, self).__init__(methodName) self.config = Config.get()
def test_parse_invalid_processes(self): self.assertIsNone(Config.parse_data(u"""[vermin] processes = -1 """))
def test_parse_print_visits(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.print_visits(), expected)
def test_parse_invalid_verbose(self): self.assertIsNone(Config.parse_data(u"""[vermin] verbose = -1 """))
def test_parse_verbose(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.verbose(), expected)
def test_parse_quiet(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.quiet(), expected)
def test_parse_invalid_targets(self, data): self.assertIsNone(Config.parse_data(data))
def __init__(self, methodName): super(VerminGeneralTests, self).__init__(methodName) self.config = Config.get()
def test_parse_show_tips(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.show_tips(), expected)
def test_parse_ignore_incomp(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.ignore_incomp(), expected)
def __init__(self, methodName): super(VerminClassMemberTests, self).__init__(methodName) self.config = Config.get()
def test_parse_invalid_section(self, data): self.assertIsNone(Config.parse_data(data))
def test_parse_pessimistic(self, data, expected): config = Config.parse_data(data) self.assertIsNotNone(config) self.assertEqual(config.pessimistic(), expected)
def __init__(self, methodName): super(VerminArgumentsTests, self).__init__(methodName) self.config = Config.get()
def test_override_from(self): other = Config() other.set_quiet(True) other.set_verbose(3) other.set_print_visits(True) other.set_processes(DEFAULT_PROCESSES + 1) other.set_ignore_incomp(True) other.set_lax(True) other.set_pessimistic(True) other.set_show_tips(False) other.set_analyze_hidden(True) other.add_exclusion("foo.bar.baz") self.assertTrue(other.add_backport("typing")) self.assertTrue(other.enable_feature("fstring-self-doc")) self.assertTrue(other.add_target("2.3")) other.set_format(vermin.formats.ParsableFormat()) self.config.override_from(other) self.assertEqual(other.quiet(), self.config.quiet()) self.assertEqual(other.verbose(), self.config.verbose()) self.assertEqual(other.print_visits(), self.config.print_visits()) self.assertEqual(other.processes(), self.config.processes()) self.assertEqual(other.ignore_incomp(), self.config.ignore_incomp()) self.assertEqual(other.lax(), self.config.lax()) self.assertEqual(other.pessimistic(), self.config.pessimistic()) self.assertEqual(other.show_tips(), self.config.show_tips()) self.assertEqual(other.analyze_hidden(), self.config.analyze_hidden()) self.assertEqual(other.exclusions(), self.config.exclusions()) self.assertEqual(other.backports(), self.config.backports()) self.assertEqual(other.features(), self.config.features()) self.assertEqual(other.targets(), self.config.targets()) self.assertEqual(other.format(), self.config.format())