mypy-test


Namemypy-test JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/orsinium-labs/mypy-test
SummaryTest mypy plugins, stubs, custom types.
upload_time2023-10-24 12:35:42
maintainerNone
docs_urlNone
authorGram
requires_python>=3.6
licenseMIT
keywords mypy testing stubs plugins typing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mypy_test

Test [mypy](https://mypy.readthedocs.io/en/stable/) plugins, stubs, custom types.

Create a Python file, add comments to lines where you expect mypy to produce an error, run `mypy_test`, and it will check if actual errors are the same as you expect.

Features:

+ **Flexible**: supports every feature supported by mypy, does not enforce a project structure.
+ **Fast**: mypy gets run only once for all files at once. Also, no patching, no config generation.
+ **Easy to learn**: run `mypy_test` with the same arguments as you would run mypy, and it just works.
+ **Lightweight**: no dependencies except mypy.

```bash
python3 -m pip install mypy-test
```

## Usage

1. Write a file you want to test, add comments to the lines you expect to fail:

    ```python
    a = 1
    reveal_type(a)  # R: builtins.int
    ```

2. Run the tool:

    ```bash
    python3 -m mypy_test example.py
    ```

## Writing the comments

+ The comments have the following format: `SEVERITY: MESSAGE`.
+ Severity is a one-letter violation severity as reported by mypy.
  + `F` for "fatal"
  + `E` for "error"
  + `W` for "warning"
  + `N` for "note"
  + `R` is a shorthand for `N: Revealed type is "..."`
+ Comment can be on the same line as the violation or on the line before.

Example:

```python
var = 1.1
reveal_type(var)  # R: builtins.float

# E: Incompatible types in assignment (expression has type "str", variable has type "float")
var = ""
```

Tips:

+ The fastest way to know the severity and the message is to run `mypy_test` on the code and then copy-paste the resulting message.
+ Make separate functions for every test case, so it can have a nice description and a clean namespace.
+ Place all test files into one directory. For example, `/types/` or `/tests/types/`.

## Alternatives

+ [pytest-mypy-plugins](https://github.com/typeddjango/pytest-mypy-plugins) - pytest plugin, test cases described in a YAML file.
+ [pytest-mypy-testing](https://github.com/davidfritzsche/pytest-mypy-testing) - pytest plugin, tests are described like pytest test cases (but they actually don't get run).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/orsinium-labs/mypy-test",
    "name": "mypy-test",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "mypy,testing,stubs,plugins,typing",
    "author": "Gram",
    "author_email": "gram@orsinium.dev",
    "download_url": "https://files.pythonhosted.org/packages/fe/42/8827ad0c9b956b070554e82c71c382090c4fc35cf09d3488eab09eb270b8/mypy_test-0.1.4.tar.gz",
    "platform": null,
    "description": "# mypy_test\n\nTest [mypy](https://mypy.readthedocs.io/en/stable/) plugins, stubs, custom types.\n\nCreate a Python file, add comments to lines where you expect mypy to produce an error, run `mypy_test`, and it will check if actual errors are the same as you expect.\n\nFeatures:\n\n+ **Flexible**: supports every feature supported by mypy, does not enforce a project structure.\n+ **Fast**: mypy gets run only once for all files at once. Also, no patching, no config generation.\n+ **Easy to learn**: run `mypy_test` with the same arguments as you would run mypy, and it just works.\n+ **Lightweight**: no dependencies except mypy.\n\n```bash\npython3 -m pip install mypy-test\n```\n\n## Usage\n\n1. Write a file you want to test, add comments to the lines you expect to fail:\n\n    ```python\n    a = 1\n    reveal_type(a)  # R: builtins.int\n    ```\n\n2. Run the tool:\n\n    ```bash\n    python3 -m mypy_test example.py\n    ```\n\n## Writing the comments\n\n+ The comments have the following format: `SEVERITY: MESSAGE`.\n+ Severity is a one-letter violation severity as reported by mypy.\n  + `F` for \"fatal\"\n  + `E` for \"error\"\n  + `W` for \"warning\"\n  + `N` for \"note\"\n  + `R` is a shorthand for `N: Revealed type is \"...\"`\n+ Comment can be on the same line as the violation or on the line before.\n\nExample:\n\n```python\nvar = 1.1\nreveal_type(var)  # R: builtins.float\n\n# E: Incompatible types in assignment (expression has type \"str\", variable has type \"float\")\nvar = \"\"\n```\n\nTips:\n\n+ The fastest way to know the severity and the message is to run `mypy_test` on the code and then copy-paste the resulting message.\n+ Make separate functions for every test case, so it can have a nice description and a clean namespace.\n+ Place all test files into one directory. For example, `/types/` or `/tests/types/`.\n\n## Alternatives\n\n+ [pytest-mypy-plugins](https://github.com/typeddjango/pytest-mypy-plugins) - pytest plugin, test cases described in a YAML file.\n+ [pytest-mypy-testing](https://github.com/davidfritzsche/pytest-mypy-testing) - pytest plugin, tests are described like pytest test cases (but they actually don't get run).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Test mypy plugins, stubs, custom types.",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/orsinium-labs/mypy-test"
    },
    "split_keywords": [
        "mypy",
        "testing",
        "stubs",
        "plugins",
        "typing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "101ed4b27126507c4299c126159f61c29b6ec925ecf9d35d210fe7b88ebab641",
                "md5": "87e341f7cd0cec44d397b4e9c4f96729",
                "sha256": "ce6bc363baefd766f4aae47eaee9bea6261feec6d0cd556efdf2386a02592871"
            },
            "downloads": -1,
            "filename": "mypy_test-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87e341f7cd0cec44d397b4e9c4f96729",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7675,
            "upload_time": "2023-10-24T12:35:41",
            "upload_time_iso_8601": "2023-10-24T12:35:41.278268Z",
            "url": "https://files.pythonhosted.org/packages/10/1e/d4b27126507c4299c126159f61c29b6ec925ecf9d35d210fe7b88ebab641/mypy_test-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fe428827ad0c9b956b070554e82c71c382090c4fc35cf09d3488eab09eb270b8",
                "md5": "5298ce13cfee23e9dea1bc5004c8d9ac",
                "sha256": "57519efe3fd23041e076f22c7dcf927a7bd542f5c07c374db5d8638417ad24ab"
            },
            "downloads": -1,
            "filename": "mypy_test-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "5298ce13cfee23e9dea1bc5004c8d9ac",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7909,
            "upload_time": "2023-10-24T12:35:42",
            "upload_time_iso_8601": "2023-10-24T12:35:42.879380Z",
            "url": "https://files.pythonhosted.org/packages/fe/42/8827ad0c9b956b070554e82c71c382090c4fc35cf09d3488eab09eb270b8/mypy_test-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-24 12:35:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "orsinium-labs",
    "github_project": "mypy-test",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mypy-test"
}
        
Elapsed time: 0.15428s