Skip to content

Commit

Permalink
added tox support
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideCanton committed Sep 16, 2024
1 parent f8e7c62 commit 0e061d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pytest_suggest/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -23,22 +21,37 @@ 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.
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.
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tox]
envlist = py39,py310,py311,py312

[testenv]
deps =
pytest-cov
commands = pytest {posargs:tests}

[pytest]
addopts = -ra --color=yes

0 comments on commit 0e061d2

Please sign in to comment.