晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/opt/cloudlinux/venv/lib/python3.11/site-packages/pylint/testutils/functional/ |
| Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/pylint/testutils/functional/test_file.py |
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
from __future__ import annotations
import configparser
import sys
from collections.abc import Callable
from os.path import basename, exists, join
def parse_python_version(ver_str: str) -> tuple[int, ...]:
"""Convert python version to a tuple of integers for easy comparison."""
return tuple(int(digit) for digit in ver_str.split("."))
class NoFileError(Exception):
pass
if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict
class TestFileOptions(TypedDict):
min_pyver: tuple[int, ...]
max_pyver: tuple[int, ...]
min_pyver_end_position: tuple[int, ...]
requires: list[str]
except_implementations: list[str]
exclude_platforms: list[str]
exclude_from_minimal_messages_config: bool
# mypy need something literal, we can't create this dynamically from TestFileOptions
POSSIBLE_TEST_OPTIONS = {
"min_pyver",
"max_pyver",
"min_pyver_end_position",
"requires",
"except_implementations",
"exclude_platforms",
"exclude_from_minimal_messages_config",
}
class FunctionalTestFile:
"""A single functional test case file with options."""
_CONVERTERS: dict[str, Callable[[str], tuple[int, ...] | list[str]]] = {
"min_pyver": parse_python_version,
"max_pyver": parse_python_version,
"min_pyver_end_position": parse_python_version,
"requires": lambda s: [i.strip() for i in s.split(",")],
"except_implementations": lambda s: [i.strip() for i in s.split(",")],
"exclude_platforms": lambda s: [i.strip() for i in s.split(",")],
}
def __init__(self, directory: str, filename: str) -> None:
self._directory = directory
self.base = filename.replace(".py", "")
# TODO: 2.x: Deprecate FunctionalTestFile.options and related code
# We should just parse these options like a normal configuration file.
self.options: TestFileOptions = {
"min_pyver": (2, 5),
"max_pyver": (4, 0),
"min_pyver_end_position": (3, 8),
"requires": [],
"except_implementations": [],
"exclude_platforms": [],
"exclude_from_minimal_messages_config": False,
}
self._parse_options()
def __repr__(self) -> str:
return f"FunctionalTest:{self.base}"
def _parse_options(self) -> None:
cp = configparser.ConfigParser()
cp.add_section("testoptions")
try:
cp.read(self.option_file)
except NoFileError:
pass
for name, value in cp.items("testoptions"):
conv = self._CONVERTERS.get(name, lambda v: v)
assert (
name in POSSIBLE_TEST_OPTIONS
), f"[testoptions]' can only contains one of {POSSIBLE_TEST_OPTIONS} and had '{name}'"
self.options[name] = conv(value) # type: ignore[literal-required]
@property
def option_file(self) -> str:
return self._file_type(".rc")
@property
def module(self) -> str:
package = basename(self._directory)
return ".".join([package, self.base])
@property
def expected_output(self) -> str:
return self._file_type(".txt", check_exists=False)
@property
def source(self) -> str:
return self._file_type(".py")
def _file_type(self, ext: str, check_exists: bool = True) -> str:
name = join(self._directory, self.base + ext)
if not check_exists or exists(name):
return name
raise NoFileError(f"Cannot find '{name}'.")
|