Skip to content

Commit

Permalink
Merge pull request #155 from netromdk/issue-144
Browse files Browse the repository at this point in the history
  • Loading branch information
netromdk committed Apr 2, 2023
2 parents fee7ede + 0136d6f commit de2fc74
Show file tree
Hide file tree
Showing 14 changed files with 701 additions and 56 deletions.
1 change: 1 addition & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"exception",
"builtin_functions",
"builtin_constants",
"builtin_exceptions",
"function",
"constants",
"decorators",
Expand Down
120 changes: 120 additions & 0 deletions tests/builtin_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from .testutils import VerminTest

class VerminBuiltinExceptionsMemberTests(VerminTest):
def test_BaseException(self):
self.assertOnlyIn(((2, 5), (3, 0)), self.detect("BaseException()"))
self.assertOnlyIn((2, 5), self.detect("from exceptions import BaseException"))

def test_BytesWarning(self):
self.assertOnlyIn(((2, 6), (3, 0)), self.detect("BytesWarning()"))
self.assertOnlyIn((2, 6), self.detect("from exceptions import BytesWarning"))

def test_UnicodeWarning(self):
self.assertOnlyIn(((2, 5), (3, 0)), self.detect("UnicodeWarning()"))
self.assertOnlyIn((2, 5), self.detect("from exceptions import UnicodeWarning"))

def test_UnicodeError(self):
self.assertOnlyIn(((2, 0), (3, 0)), self.detect("UnicodeError()"))
self.assertOnlyIn((2, 0), self.detect("from exceptions import UnicodeError"))

def test_GeneratorExit(self):
self.assertOnlyIn(((2, 5), (3, 0)), self.detect("GeneratorExit()"))
self.assertOnlyIn((2, 5), self.detect("from exceptions import GeneratorExit"))

def test_ImportWarning(self):
self.assertOnlyIn(((2, 5), (3, 0)), self.detect("ImportWarning()"))
self.assertOnlyIn((2, 5), self.detect("from exceptions import ImportWarning"))

def test_StopIteration(self):
self.assertOnlyIn(((2, 2), (3, 0)), self.detect("StopIteration()"))
self.assertOnlyIn((2, 2), self.detect("from exceptions import StopIteration"))

def test_UnboundLocalError(self):
self.assertOnlyIn(((2, 0), (3, 0)), self.detect("UnboundLocalError()"))
self.assertOnlyIn((2, 0), self.detect("from exceptions import UnboundLocalError"))

def test_UnicodeDecodeError(self):
self.assertOnlyIn(((2, 3), (3, 0)), self.detect("UnicodeDecodeError()"))
self.assertOnlyIn((2, 3), self.detect("from exceptions import UnicodeDecodeError"))

def test_UnicodeEncodeError(self):
self.assertOnlyIn(((2, 3), (3, 0)), self.detect("UnicodeEncodeError()"))
self.assertOnlyIn((2, 3), self.detect("from exceptions import UnicodeEncodeError"))

def test_UnicodeTranslateError(self):
self.assertOnlyIn(((2, 3), (3, 0)), self.detect("UnicodeTranslateError()"))
self.assertOnlyIn((2, 3), self.detect("from exceptions import UnicodeTranslateError"))

def test_WindowsError(self):
self.assertOnlyIn(((2, 0), (3, 0)), self.detect("WindowsError()"))
self.assertOnlyIn((2, 0), self.detect("from exceptions import WindowsError"))

def test_ReferenceError(self):
self.assertOnlyIn(((2, 2), (3, 0)), self.detect("ReferenceError()"))
self.assertOnlyIn((2, 2), self.detect("from exceptions import ReferenceError"))

def test_ExceptionGroup(self):
self.assertOnlyIn((3, 11), self.detect("ExceptionGroup()"))

def test_BaseExceptionGroup(self):
self.assertOnlyIn((3, 11), self.detect("BaseExceptionGroup()"))

def test_BlockingIOError(self):
self.assertOnlyIn((3, 3), self.detect("BlockingIOError()"))

def test_BrokenPipeError(self):
self.assertOnlyIn((3, 3), self.detect("BrokenPipeError()"))

def test_ChildProcessError(self):
self.assertOnlyIn((3, 3), self.detect("ChildProcessError()"))

def test_ConnectionAbortedError(self):
self.assertOnlyIn((3, 3), self.detect("ConnectionAbortedError()"))

def test_ConnectionError(self):
self.assertOnlyIn((3, 3), self.detect("ConnectionError()"))

def test_ConnectionRefusedError(self):
self.assertOnlyIn((3, 3), self.detect("ConnectionRefusedError()"))

def test_ConnectionResetError(self):
self.assertOnlyIn((3, 3), self.detect("ConnectionResetError()"))

def test_EncodingWarning(self):
self.assertOnlyIn((3, 10), self.detect("EncodingWarning()"))

def test_FileExistsError(self):
self.assertOnlyIn((3, 3), self.detect("FileExistsError()"))

def test_FileNotFoundError(self):
self.assertOnlyIn((3, 3), self.detect("FileNotFoundError()"))

def test_InterruptedError(self):
self.assertOnlyIn((3, 3), self.detect("InterruptedError()"))

def test_IsADirectoryError(self):
self.assertOnlyIn((3, 3), self.detect("IsADirectoryError()"))

def test_ModuleNotFoundError(self):
self.assertOnlyIn((3, 6), self.detect("ModuleNotFoundError()"))

def test_NotADirectoryError(self):
self.assertOnlyIn((3, 3), self.detect("NotADirectoryError()"))

def test_PermissionError(self):
self.assertOnlyIn((3, 3), self.detect("PermissionError()"))

def test_ProcessLookupError(self):
self.assertOnlyIn((3, 3), self.detect("ProcessLookupError()"))

def test_RecursionError(self):
self.assertOnlyIn((3, 5), self.detect("RecursionError()"))

def test_ResourceWarning(self):
self.assertOnlyIn((3, 2), self.detect("ResourceWarning()"))

def test_StopAsyncIteration(self):
self.assertOnlyIn((3, 5), self.detect("StopAsyncIteration()"))

def test_TimeoutError(self):
self.assertOnlyIn((3, 3), self.detect("TimeoutError()"))
12 changes: 12 additions & 0 deletions tests/builtin_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ def test_copy_of_list(self, source, min_versions):
def test_decode_of_str(self, source, min_versions):
self.assertDetectMinVersions(source, min_versions)

@VerminTest.parameterized_args([
("s=\"\"\ns.encode()", ((2, 0), (3, 0))),
("\"\".encode()", ((2, 0), (3, 0))),
("s=str()\ns.encode()", ((2, 0), (3, 0))),
("str().encode()", ((2, 0), (3, 0))),
])
def test_encode_of_str(self, source, min_versions):
self.assertDetectMinVersions(source, min_versions)

@VerminTest.parameterized_args([
("s=\"\"\ns.casefold()", (3, 3)),
("\"\".casefold()", (3, 3)),
Expand Down Expand Up @@ -458,3 +467,6 @@ def test_aiter(self):

def test_anext(self):
self.assertOnlyIn((3, 10), self.detect("anext()"))

def test_zip(self):
self.assertOnlyIn(((2, 0), (3, 0)), self.detect("zip()"))
36 changes: 33 additions & 3 deletions tests/class.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def test_PidfdChildWatcher_of_asyncio(self):
def test_Runner_of_asyncio(self):
self.assertOnlyIn((3, 11), self.detect("from asyncio import Runner"))

def test_TaskGroup_of_asyncio(self):
self.assertOnlyIn((3, 11), self.detect("from asyncio import TaskGroup"))

def test_Calendar_of_calendar(self):
self.assertOnlyIn(((2, 5), (3, 0)), self.detect("from calendar import Calendar"))

Expand Down Expand Up @@ -97,6 +100,15 @@ def test_SystemRandom_of_random(self):
def test_DevpollSelector_of_selectors(self):
self.assertOnlyIn((3, 5), self.detect("from selectors import DevpollSelector"))

def test_Handlers_of_signals(self):
self.assertOnlyIn((3, 5), self.detect("from signals import Handlers"))

def test_Sigmasks_of_signals(self):
self.assertOnlyIn((3, 5), self.detect("from signals import Sigmasks"))

def test_Signals_of_signals(self):
self.assertOnlyIn((3, 5), self.detect("from signals import Signals"))

def test_Barrier_of_multiprocessing(self):
self.assertOnlyIn((3, 3), self.detect("from multiprocessing import Barrier"))

Expand Down Expand Up @@ -369,6 +381,12 @@ def test_SSLErrorNumber_of_ssl(self):
def test_TLSVersion_of_ssl(self):
self.assertOnlyIn((3, 7), self.detect("from ssl import TLSVersion"))

def test_VerifyFlags_of_ssl(self):
self.assertOnlyIn((3, 6), self.detect("from ssl import VerifyFlags"))

def test_VerifyMode_of_ssl(self):
self.assertOnlyIn((3, 6), self.detect("from ssl import VerifyMode"))

def test_Formatter_of_string(self):
self.assertOnlyIn(((2, 6), (3, 0)), self.detect("from string import Formatter"))

Expand All @@ -382,13 +400,25 @@ def test_CompletedProcess_of_subprocess(self):
self.assertOnlyIn((3, 5), self.detect("from subprocess import CompletedProcess"))

def test_EnvironmentVarGuard_of_test_support(self):
self.assertOnlyIn(((2, 6), (3, 0)), self.detect("from test.support import EnvironmentVarGuard"))
self.assertOnlyIn((2, 6), self.detect("from test.support import EnvironmentVarGuard"))

def test_TransientResource_of_test_support(self):
self.assertOnlyIn(((2, 6), (3, 0)), self.detect("from test.support import TransientResource"))
self.assertOnlyIn((2, 6), self.detect("from test.support import TransientResource"))

def test_WarningsRecorder_of_test_support(self):
self.assertOnlyIn(((2, 6), (3, 0)), self.detect("from test.support import WarningsRecorder"))
self.assertOnlyIn((2, 6), self.detect("from test.support import WarningsRecorder"))

def test_EnvironmentVarGuard_of_test_support_os_helper(self):
self.assertOnlyIn((3, 10),
self.detect("from test.support.os_helper import EnvironmentVarGuard"))

def test_TransientResource_of_test_support_socket_helper(self):
self.assertOnlyIn((3, 9),
self.detect("from test.support.socket_helper import TransientResource"))

def test_WarningsRecorder_of_test_support_warnings_helper(self):
self.assertOnlyIn((3, 10),
self.detect("from test.support.warnings_helper import WarningsRecorder"))

def test_Barrier_of_threading(self):
self.assertOnlyIn((3, 2), self.detect("from threading import Barrier"))
Expand Down
40 changes: 35 additions & 5 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def test_OP_NO_TLSv1_2_of_ssl(self):
self.assertOnlyIn(((2, 7), (3, 4)), self.detect("from ssl import OP_NO_TLSv1_2"))

def test_OP_NO_TLSv1_3_of_ssl(self):
self.assertOnlyIn(((2, 7), (3, 6)), self.detect("from ssl import OP_NO_TLSv1_3"))
self.assertOnlyIn(((2, 7), (3, 7)), self.detect("from ssl import OP_NO_TLSv1_3"))

def test_OP_CIPHER_SERVER_PREFERENCE_of_ssl(self):
self.assertOnlyIn(((2, 7), (3, 3)), self.detect("from ssl import OP_CIPHER_SERVER_PREFERENCE"))
Expand Down Expand Up @@ -494,6 +494,9 @@ def test_stem_of_Path_of_zipfile(self):
def test_suffixes_of_Path_of_zipfile(self):
self.assertOnlyIn((3, 11), self.detect("from zipfile import Path\nPath().suffixes"))

def test_KW_ONLY_of_dataclasses(self):
self.assertOnlyIn((3, 10), self.detect("import dataclasses\ndataclasses.KW_ONLY"))

def test_METHOD_SHA512_of_crypt(self):
self.assertOnlyIn((3, 3), self.detect("import crypt\ncrypt.METHOD_SHA512"))

Expand Down Expand Up @@ -680,6 +683,12 @@ def test_MADV_DODUMP_of_mmap(self):
def test_MADV_FREE_of_mmap(self):
self.assertOnlyIn((3, 8), self.detect("import mmap\nmmap.MADV_FREE"))

def test_MADV_FREE_REUSABLE_of_mmap(self):
self.assertOnlyIn((3, 8), self.detect("import mmap\nmmap.MADV_FREE_REUSABLE"))

def test_MADV_FREE_REUSE_of_mmap(self):
self.assertOnlyIn((3, 8), self.detect("import mmap\nmmap.MADV_FREE_REUSE"))

def test_MADV_NOSYNC_of_mmap(self):
self.assertOnlyIn((3, 8), self.detect("import mmap\nmmap.MADV_NOSYNC"))

Expand Down Expand Up @@ -1172,10 +1181,10 @@ def test_terminator_from_logging_StreamHandler(self):
self.detect("from logging import StreamHandler\n"
"StreamHandler().terminator"))

def test_name_from_logging_handlers_BaseRotatingHandler(self):
def test_namer_from_logging_handlers_BaseRotatingHandler(self):
self.assertOnlyIn((3, 3),
self.detect("from logging.handlers import BaseRotatingHandler\n"
"BaseRotatingHandler().name"))
"BaseRotatingHandler().namer"))

def test_rotator_from_logging_handlers_BaseRotatingHandler(self):
self.assertOnlyIn((3, 3),
Expand Down Expand Up @@ -1687,6 +1696,12 @@ def test_is_async_from_pyclbr_Function(self):
def test_NOFLAG_of_re(self):
self.assertOnlyIn((3, 11), self.detect("from re import NOFLAG"))

def test_U_of_re(self):
self.assertOnlyIn(((2, 0), (3, 0)), self.detect("from re import U"))

def test_UNICODE_of_re(self):
self.assertOnlyIn(((2, 0), (3, 0)), self.detect("from re import UNICODE"))

def test_colno_from_re_error(self):
self.assertOnlyIn((3, 5),
self.detect("from re import error\n"
Expand All @@ -1712,6 +1727,11 @@ def test_pos_from_re_error(self):
self.detect("from re import error\n"
"error().pos"))

def test_fillvalue_from_reprlib_Repr(self):
self.assertOnlyIn((3, 11),
self.detect("from reprlib import Repr\n"
"Repr().fillvalue"))

def test_maxfrozenset_from_repr_Repr(self):
self.assertOnlyIn((2, 4),
self.detect("from repr import Repr\n"
Expand Down Expand Up @@ -2355,6 +2375,11 @@ def test_in_transaction_from_sqlite3_Connection(self):
self.detect("from sqlite3 import Connection\n"
"Connection().in_transaction"))

def test_iterdump_from_sqlite3_Connection(self):
self.assertOnlyIn(((2, 6), (3, 0)),
self.detect("from sqlite3 import Connection\n"
"Connection().iterdump"))

def test_sqlite_errorcode_from_sqlite3_Error(self):
self.assertOnlyIn((3, 11),
self.detect("from sqlite3 import Error\n"
Expand Down Expand Up @@ -2797,6 +2822,11 @@ def test_NL_of_token(self):
def test_TYPE_COMMENT_of_token(self):
self.assertOnlyIn((3, 8), self.detect("from token import TYPE_COMMENT"))

def test___notes___from_traceback_TracebackException(self):
self.assertOnlyIn((3, 11),
self.detect("from traceback import TracebackException\n"
"TracebackException().__notes__"))

def test_domain_from_tracemalloc_Filter(self):
self.assertOnlyIn((3, 6),
self.detect("from tracemalloc import Filter\n"
Expand Down Expand Up @@ -2836,7 +2866,7 @@ def test_NoneType_of_types(self):
self.assertOnlyIn(((2, 0), (3, 10)), self.detect("from types import NoneType"))

def test_NotImplementedType_of_types(self):
self.assertOnlyIn(((2, 0), (3, 10)), self.detect("from types import NotImplementedType"))
self.assertOnlyIn(((2, 5), (3, 10)), self.detect("from types import NotImplementedType"))

def test_EllipsisType_of_types(self):
self.assertOnlyIn(((2, 0), (3, 10)), self.detect("from types import EllipsisType"))
Expand Down Expand Up @@ -2923,7 +2953,7 @@ def test_Unpack_of_typing(self):
self.assertOnlyIn((3, 11), self.detect("from typing import Unpack"))

def test_ucd_3_2_0_of_unicodedata(self):
self.assertOnlyIn(((2, 3), (3, 0)), self.detect("from unicodedata import ucd_3_2_0"))
self.assertOnlyIn(((2, 5), (3, 0)), self.detect("from unicodedata import ucd_3_2_0"))

def test_unidata_version_of_unicodedata(self):
self.assertOnlyIn(((2, 3), (3, 0)), self.detect("from unicodedata import unidata_version"))
Expand Down
9 changes: 9 additions & 0 deletions tests/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ def test_abstractstaticmethod_of_abc(self):
def test_asynccontextmanager_of_contextlib(self):
self.assertOnlyIn((3, 7), self.detect("from contextlib import asynccontextmanager"))

def test_global_enum_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import global_enum"))

def test_member_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import member"))

def test_nonmember_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import nonmember"))

def test_property_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import property"))

Expand Down
2 changes: 1 addition & 1 deletion tests/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_SkipTest_of_unittest(self):
self.assertOnlyIn(((2, 7), (3, 1)), self.detect("from unittest import SkipTest"))

def test_ContentTooShortError_of_urllib(self):
self.assertOnlyIn((2, 6), self.detect("from urllib import ContentTooShortError"))
self.assertOnlyIn((2, 5), self.detect("from urllib import ContentTooShortError"))

def test_DOMException_of_xml_dom(self):
self.assertOnlyIn(((2, 1), (3, 0)), self.detect("from xml.dom import DOMException"))
Expand Down
1 change: 1 addition & 0 deletions tests/exclusions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def test_module(self):
visitor = self.visit("from email.parser import FeedParser")
self.assertEqual([(2, 4), (3, 0)], visitor.minimum_versions())

self.config.add_exclusion("email.parser")
self.config.add_exclusion("email.parser.FeedParser")
visitor = self.visit("from email.parser import FeedParser")
self.assertEqual([(0, 0), (0, 0)], visitor.minimum_versions())
Expand Down
Loading

0 comments on commit de2fc74

Please sign in to comment.