Skip to main content

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'))).

Metadata

Release files for teyit 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for teyit 0.4.3
File Size Uploaded Provenance
teyit-0.4.3.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for teyit 0.4.3
File Interpreter ABI Platform
teyit-0.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.2 kB

Release files / teyit-0.4.3.tar.gz

Download URL teyit-0.4.3.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c74cdec17f25e68176778ea6f00afae2e97344e97b4a6e63b3a4cdca6f1290ab
BLAKE2b-256 checksum
How to use checksums
fcc89c7b0569e4b8587301b75200cd9454752d22d17966947508f2dd05cde10a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / teyit-0.4.3-py3-none-any.whl

Download URL teyit-0.4.3-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af6681d18b47be3e63fe3ccb310948617e691eb94004d205e54be9a74cb79cff
BLAKE2b-256 checksum
How to use checksums
e7cd2a65fb71a147807c33eedef519cdf17a70f4d28ebf2a78346b196b5b9528
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for teyit 0.4.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page