From 0e061d2eea5307e8c5e90a2e9a25f3f9f98caca5 Mon Sep 17 00:00:00 2001 From: Davide Canton Date: Mon, 16 Sep 2024 15:57:40 +0200 Subject: [PATCH] added tox support --- pytest_suggest/trie.py | 23 ++++++++++++++++++----- setup.cfg | 1 + tox.ini | 10 ++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 tox.ini diff --git a/pytest_suggest/trie.py b/pytest_suggest/trie.py index 0825d9c..efc1aff 100644 --- a/pytest_suggest/trie.py +++ b/pytest_suggest/trie.py @@ -3,11 +3,9 @@ import pickle import weakref from collections.abc import Generator, Iterable -from dataclasses import dataclass, field from typing import BinaryIO -@dataclass(slots=True, weakref_slot=True) class Node: """A node in a trie.""" @@ -23,15 +21,15 @@ class Node: so for example if the prefix is "abc" and this node represents "ab", then this value is 2. """ - children: dict[str, Node] = field(default_factory=dict) + children: dict[str, Node] """The children of this node. This is a mapping of the first character of the child to the child node. """ - is_word: bool = False + is_word: bool """Whether this node represents a word in the trie or just a prefix.""" - parent: Node | None = field(default=None, repr=False, init=False) + parent: Node | None """The parent of this node. This is a weak reference to the parent node. @@ -39,6 +37,21 @@ class Node: The root node has no parent and this value is None. """ + __slots__ = ("prefix", "part_len", "children", "is_word", "parent", "__weakref__") + + def __init__( + self, + prefix: str, + part_len: int, + children: dict[str, Node] | None = None, + is_word: bool = False, + ) -> None: + self.prefix = prefix + self.part_len = part_len + self.children = children or {} + self.is_word = is_word + self.parent = None + @staticmethod def root() -> Node: """Creates the root node. diff --git a/setup.cfg b/setup.cfg index d4d7d09..27f2ad1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,6 +17,7 @@ include = pytest_suggest* dev = pytest-cov>=4.0.0 build + tox # code coverage configuration # refer to https://coverage.readthedocs.io/en/latest/config.html diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..3533837 --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +envlist = py39,py310,py311,py312 + +[testenv] +deps = + pytest-cov +commands = pytest {posargs:tests} + +[pytest] +addopts = -ra --color=yes