Skip to content

Commit

Permalink
fix tests for < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Jun 4, 2024
1 parent 05302b1 commit 5ccb40c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
12 changes: 11 additions & 1 deletion django_routines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class RoutineCommand:
"""


# todo - remove this and replace with key argument when support for python <3.10 dropped.
def insort_right_with_key(a, x, key=lambda x: x):
transformed_list = [key(item) for item in a]
transformed_x = key(x)
insert_point = bisect.bisect_right(transformed_list, transformed_x)
a.insert(insert_point, x)


@dataclass
class Routine:
"""
Expand Down Expand Up @@ -101,7 +109,9 @@ def plan(self, switches: Set[str]) -> List[RoutineCommand]:
]

def command(self, command: RoutineCommand):
bisect.insort(self.commands, command, key=lambda cmd: cmd.priority)
# python >= 3.10
# bisect.insort(self.commands, command, key=lambda cmd: cmd.priority)
insort_right_with_key(self.commands, command, key=lambda cmd: cmd.priority)
return command


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Command(TyperCommand, rich_markup_mode="rich"): # type: ignore
verbosity: int = 1
switches: t.Set[str] = set()

suppressed_base_arguments: t.Optional[t.Iterable[str]] = None
suppressed_base_arguments = set()

_routine: t.Optional[Routine] = None
_verbosity_passed: bool = False
Expand Down
62 changes: 60 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pexpect = "^4.9.0"
pyright = "^1.1.357"
ruff = "^0.4.1"
django-stubs = "^5.0.2"
mypy = "^1.10.0"

[tool.poetry.extras]
rich = ["rich"]
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_command(self, no_color=True, verbosity=None):
passed_options.clear()

command = (
"routines",
"routine",
("--no-color" if no_color else "--force-color"),
*(("--verbosity", str(verbosity)) if verbosity is not None else tuple()),
"test",
Expand Down Expand Up @@ -126,9 +126,9 @@ def test_verbosity(self):

def test_list(self, no_color=True):
if no_color:
command = ("routines", "--no-color", "test")
command = ("routine", "--no-color", "test")
else:
command = ("routines", "--force-color", "test")
command = ("routine", "--force-color", "test")

out = StringIO()
call_command(*command, "--all", "list", stdout=out)
Expand Down

0 comments on commit 5ccb40c

Please sign in to comment.