Skip to main content

Unittest assertion formatter

Project description

Teyit

An analyzer / formatter for your Python unit tests (more specifically, the tests written with the unittest module).

Usage

usage: teyit [-h] [--pattern PATTERN] [--show-stats] [--fail-on-change] [paths ...]

positional arguments:
  paths

optional arguments:
  -h, --help         show this help message and exit
  --pattern PATTERN  Wildcard pattern for capturing test files.
  --show-stats       Print out some debug stats related about refactorings
  --fail-on-change   Exit with status code 1 if any file changed

Pre-commit Hook

-   repo: https://github.com/isidentical/teyit
    rev: master
    hooks:
    -   id: teyit

Examples

Here are some examples from CPython's test suite:

--- a/Lib/test/test_telnetlib.py
+++ b/Lib/test/test_telnetlib.py
@@ -48,7 +48,7 @@ def testContextManager(self):
         self.assertIsNone(tn.get_socket())

     def testTimeoutDefault(self):
-        self.assertTrue(socket.getdefaulttimeout() is None)
+        self.assertIsNone(socket.getdefaulttimeout())
         socket.setdefaulttimeout(30)
         try:
             telnet = telnetlib.Telnet(HOST, self.port)
@@ -215,7 +215,7 @@ def test_read_some(self):
         # test 'at least one byte'
         telnet = test_telnet([b'x' * 500])
         data = telnet.read_some()
-        self.assertTrue(len(data) >= 1)
+        self.assertGreaterEqual(len(data), 1)
         # test EOF
         telnet = test_telnet()
         data = telnet.read_some()
--- a/Lib/test/test___future__.py
+++ b/Lib/test/test___future__.py
@@ -13,8 +13,9 @@ def test_names(self):
         for name in dir(__future__):
             obj = getattr(__future__, name, None)
             if obj is not None and isinstance(obj, __future__._Feature):
-                self.assertTrue(
-                    name in given_feature_names,
+                self.assertIn(
+                    name,
+                    given_feature_names,
                     "%r should have been in all_feature_names" % name
                 )
                 given_feature_names.remove(name)
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -321,14 +321,14 @@ class A(metaclass=abc_ABCMeta):
             class B:
                 pass
             b = B()
-            self.assertFalse(isinstance(b, A))
-            self.assertFalse(isinstance(b, (A,)))
+            self.assertNotIsInstance(b, A)
+            self.assertNotIsInstance(b, (A,))
--- a/Lib/test/test_bigmem.py
+++ b/Lib/test/test_bigmem.py
@@ -536,25 +536,25 @@ def test_contains(self, size):
         edge = _('-') * (size // 2)
         s = _('').join([edge, SUBSTR, edge])
         del edge
-        self.assertTrue(SUBSTR in s)
-        self.assertFalse(SUBSTR * 2 in s)
-        self.assertTrue(_('-') in s)
-        self.assertFalse(_('a') in s)
+        self.assertIn(SUBSTR, s)
+        self.assertNotIn(SUBSTR * 2, s)
+        self.assertIn(_('-'), s)
+        self.assertNotIn(_('a'), s)

Public API

teyit.refactor(source: str, **kwargs) -> str

Shortcut to refactor_until_deterministic, for only retrieving the source code.

def refactor_until_deterministic(source: str, blacklist: FrozenSet[str] = frozenset(), *, max: int = 5) -> Tuple[str, List[Rewrite]]

Run rewrite_source until it can't refactor no more (or the max limit reached).

def rewrite_source(source: str, *, blacklist: FrozenSet[str] = frozenset()): -> Tuple[str, List[Rewrite]]

Refactor the source code changing assertion cases to the right forms. The blacklist parameter is a frozenset of functions that shouldn't refactored (e.g: frozenset(('assertX', 'assertY'))).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

teyit-0.4.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

teyit-0.4.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file teyit-0.4.1.tar.gz.

File metadata

  • Download URL: teyit-0.4.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for teyit-0.4.1.tar.gz
Algorithm Hash digest
SHA256 b676dd4dfffc0d3cf492eaaa5ada4d47cebf886cfc460836d0c9c9089d1b7d0b
MD5 b04d690f2de404d5eae16a34b8985c8b
BLAKE2b-256 98dcbe464a669e5a8fc95195ae7c2b59ade7f44a582fb910c8d6378e1d3f98b8

See more details on using hashes here.

File details

Details for the file teyit-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: teyit-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for teyit-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce04df4071188d6a7a7dbc0291aa2d2c1657a81acd3e32460fb446ce7afea6ef
MD5 09422ad18a3c7ead40f7a2f61e874fa2
BLAKE2b-256 e8b4d54c498b3bde8d1d38776cc32fab2f2252c03f6a423c96b976db10cd2c83

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page