Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/cranberry/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def metavar(self) -> str:
# Public factory functions
# ---------------------------------------------------------------------------
def option(
short: str,
long: str,
short: str | None,
long: str | None,
*,
help: str = "",
default: Any = None,
Expand All @@ -116,8 +116,8 @@ def option(


def flag(
short: str,
long: str,
short: str | None,
long: str | None,
*,
help: str = "",
default: bool = False,
Expand Down Expand Up @@ -159,8 +159,8 @@ def arg(


def file(
short: str,
long: str,
short: str | None,
long: str | None,
*,
help: str = "",
default: Any = None,
Expand All @@ -183,8 +183,8 @@ def file(


def dir(
short: str,
long: str,
short: str | None,
long: str | None,
*,
help: str = "",
default: Any = None,
Expand Down
30 changes: 30 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ def test_validate_stored(self):
spec = cb.option("-o", "--opt", validate=v)
assert spec.validate is v

def test_none_short(self):
spec = cb.option(None, "--opt")
assert spec.short is None
assert spec.long is not None

def test_none_long(self):
spec = cb.option("--opt", None)
assert spec.short is not None
assert spec.long is None


# ---------------------------------------------------------------------------
# flag()
Expand All @@ -82,6 +92,22 @@ def test_default_false(self):
def test_default_true(self):
assert cb.flag("-f", "--flag", default=True).default is True

def test_stackable_false(self):
assert cb.flag("-f", "--flag").stackable is False

def test_stackable_true(self):
assert cb.flag("-f", "--flag", stackable=True).stackable is True

def test_none_short(self):
spec = cb.flag(None, "--flag")
assert spec.short is None
assert spec.long is not None

def test_none_long(self):
spec = cb.flag("--flag", None)
assert spec.short is not None
assert spec.long is None


# ---------------------------------------------------------------------------
# arg()
Expand All @@ -105,6 +131,10 @@ def test_enforce_count_default_false(self):
def test_enforce_count_true(self):
assert cb.arg(enforce_count=True).enforce_count is True

def test_type(self):
assert cb.arg(type=int).type is int
assert cb.arg(type=str).type is str


# ---------------------------------------------------------------------------
# file()
Expand Down
Loading