Skip to content

Commit 98f3bba

Browse files
committed
Updated name of project, added tests and updated pyproject.toml
1 parent c514ca6 commit 98f3bba

File tree

10 files changed

+131
-4
lines changed

10 files changed

+131
-4
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.testing.pytestArgs": ["tests"],
3+
"python.testing.unittestEnabled": false,
4+
"python.testing.pytestEnabled": true
5+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Click With Alias
1+
# Click With Aliasing
22

33
Easily add aliases to your Click groups and commands.
File renamed without changes.
File renamed without changes.
File renamed without changes.

click_with_alias/command.py renamed to click_with_aliasing/command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def command(
1111
name: str, *args, aliases: list[str] = None, **kwargs
1212
) -> click.Command:
1313
"""
14-
The command decorator with aliasing support which replaces the default Click command decorator.
14+
The command decorator with aliasing support which
15+
replaces the default Click command decorator.
1516
1617
Usage:
1718
@command(name="my_command)
File renamed without changes.

pyproject.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
[project]
2-
name = "click_with_alias"
2+
name = "click_with_aliasing"
33
version = "1.0.0"
44
description = "Easily add aliases to your Click groups and commands."
55
authors = [
66
{ name = "Marcus Fredriksson", email = "marcus@marcusfredriksson.com" },
77
]
8+
classifiers = [
9+
"License :: OSI Approved :: MIT License",
10+
"Programming Language :: Python :: 3",
11+
"Operating System :: OS Independent",
12+
]
813
license = { file = "LICENSE" }
914
requires-python = ">=3.11"
1015
readme = "README.md"
1116
dependencies = ["click>=8.1.8"]
17+
keywords = ["click", "alias", "group", "command"]
1218

1319
[project.optional-dependencies]
1420
dev = [
@@ -24,7 +30,8 @@ requires = ["setuptools", "wheel"]
2430
build-backend = "setuptools.build_meta"
2531

2632
[tool.setuptools]
27-
packages = ["click_with_alias"]
33+
packages = ["click_with_aliasing"]
34+
py-modules = ["cwa"]
2835

2936
[tool.black]
3037
line-length = 80
@@ -33,3 +40,7 @@ target-version = ['py311']
3340
[tool.isort]
3441
profile = "black"
3542
line_length = 80
43+
44+
[project.urls]
45+
Homepage = "https://github.com/marcusfrdk/click-with-aliasing"
46+
Issues = "https://github.com/marcusfrdk/click-with-aliasing/issues"

tests/test_command.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
""" Test the command decorator and the AliasedCommand class. """
2+
3+
# pylint: disable=W0621
4+
5+
import click
6+
import pytest
7+
from click.testing import CliRunner
8+
9+
from click_with_aliasing import command, group
10+
11+
12+
@command(name="test_command", aliases=["tc", "tcmd"])
13+
def cmd():
14+
"""A simple test command."""
15+
click.echo("Test command executed")
16+
17+
18+
@group()
19+
def cli():
20+
"""A simple Click group."""
21+
22+
23+
cli.add_command(cmd)
24+
25+
26+
@pytest.fixture
27+
def runner():
28+
"""Fixture for invoking Click commands."""
29+
return CliRunner()
30+
31+
32+
def test_command_name():
33+
"""Test that the command name is correctly assigned."""
34+
assert cmd.name == "test_command"
35+
36+
37+
def test_command_aliases():
38+
"""Test that aliases are correctly assigned."""
39+
assert hasattr(cmd, "aliases")
40+
assert cmd.aliases == ["tc", "tcmd"]
41+
42+
43+
def test_command_execution(runner: CliRunner):
44+
"""Test that the command runs successfully."""
45+
result = runner.invoke(cli, ["test_command"])
46+
assert result.exit_code == 0
47+
assert "Test command executed" in result.output
48+
49+
50+
def test_command_alias_execution(runner: CliRunner):
51+
"""Test that the command executes via its alias."""
52+
for alias in ["tc", "tcmd"]:
53+
result = runner.invoke(cli, [alias])
54+
assert result.exit_code == 0
55+
assert "Test command executed" in result.output

tests/test_group.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
""" Tests for the group decorator. """
2+
3+
# pylint: disable=W0621
4+
5+
import click
6+
import pytest
7+
from click.testing import CliRunner
8+
9+
from click_with_aliasing import command, group
10+
11+
12+
@command(name="test_command", aliases=["tc", "tcmd"])
13+
def cmd():
14+
"""A simple test command."""
15+
click.echo("Test command executed")
16+
17+
18+
@group(name="test_group", aliases=["tg", "tgrp"])
19+
def grp():
20+
"""A simple test group."""
21+
22+
23+
grp.add_command(cmd)
24+
25+
26+
@pytest.fixture
27+
def runner():
28+
"""Fixture for invoking Click commands."""
29+
return CliRunner()
30+
31+
32+
def test_group_name():
33+
"""Test that the group name is correctly assigned."""
34+
assert grp.name == "test_group"
35+
36+
37+
def test_group_aliases():
38+
"""Test that aliases are correctly assigned to the group."""
39+
assert hasattr(grp, "aliases")
40+
assert grp.aliases == ["tg", "tgrp"]
41+
42+
43+
def test_group_command_execution(runner: CliRunner):
44+
"""Test that the command within the group runs successfully."""
45+
result = runner.invoke(grp, ["test_command"])
46+
assert result.exit_code == 0
47+
assert "Test command executed" in result.output
48+
49+
50+
def test_group_command_alias_execution(runner: CliRunner):
51+
"""Test that the command within the group executes via its alias."""
52+
for alias in ["tc", "tcmd"]:
53+
result = runner.invoke(grp, [alias])
54+
assert result.exit_code == 0
55+
assert "Test command executed" in result.output

0 commit comments

Comments
 (0)