File: pycodestyle_test.py

package info (click to toggle)
python-flake8 7.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,212 kB
  • sloc: python: 6,592; sh: 21; makefile: 19
file content (35 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import annotations

import importlib.machinery
import importlib.util
import os.path

import flake8.plugins.pycodestyle

HERE = os.path.dirname(os.path.abspath(__file__))


def test_up_to_date():
    """Validate that the generated pycodestyle plugin is up to date.

    We generate two "meta" plugins for pycodestyle to avoid calling overhead.

    To regenerate run:

        ./bin/gen-pycodestyle-plugin > src/flake8/plugins/pycodestyle.py
    """

    path = os.path.join(HERE, "../../../bin/gen-pycodestyle-plugin")
    name = os.path.basename(path)
    loader = importlib.machinery.SourceFileLoader(name, path)
    spec = importlib.util.spec_from_loader(loader.name, loader)
    assert spec is not None
    mod = importlib.util.module_from_spec(spec)
    loader.exec_module(mod)

    expected = "".join(f"{line}\n" for line in mod.lines())

    with open(flake8.plugins.pycodestyle.__file__) as f:
        contents = f.read()

    assert contents == expected