fixed subscription table

This commit is contained in:
2025-02-02 00:02:31 -05:00
parent a1ab31acfe
commit ef5f57e678
5389 changed files with 686710 additions and 28 deletions

View File

@@ -0,0 +1,59 @@
from __future__ import annotations
from typing import Any
from unittest import TestCase
from traitlets import TraitError
class TraitTestBase(TestCase):
"""A best testing class for basic trait types."""
def assign(self, value: Any) -> None:
self.obj.value = value # type:ignore[attr-defined]
def coerce(self, value: Any) -> Any:
return value
def test_good_values(self) -> None:
if hasattr(self, "_good_values"):
for value in self._good_values:
self.assign(value)
self.assertEqual(self.obj.value, self.coerce(value)) # type:ignore[attr-defined]
def test_bad_values(self) -> None:
if hasattr(self, "_bad_values"):
for value in self._bad_values:
try:
self.assertRaises(TraitError, self.assign, value)
except AssertionError:
raise AssertionError(value) from None
def test_default_value(self) -> None:
if hasattr(self, "_default_value"):
self.assertEqual(self._default_value, self.obj.value) # type:ignore[attr-defined]
def test_allow_none(self) -> None:
if (
hasattr(self, "_bad_values")
and hasattr(self, "_good_values")
and None in self._bad_values
):
trait = self.obj.traits()["value"] # type:ignore[attr-defined]
try:
trait.allow_none = True
self._bad_values.remove(None)
# skip coerce. Allow None casts None to None.
self.assign(None)
self.assertEqual(self.obj.value, None) # type:ignore[attr-defined]
self.test_good_values()
self.test_bad_values()
finally:
# tear down
trait.allow_none = False
self._bad_values.append(None)
def tearDown(self) -> None:
# restore default value after tests, if set
if hasattr(self, "_default_value"):
self.obj.value = self._default_value # type:ignore[attr-defined]

View File

@@ -0,0 +1,42 @@
from __future__ import annotations
import sys
from subprocess import PIPE, Popen
from typing import Any, Sequence
def get_output_error_code(cmd: str | Sequence[str]) -> tuple[str, str, Any]:
"""Get stdout, stderr, and exit code from running a command"""
p = Popen(cmd, stdout=PIPE, stderr=PIPE) # noqa: S603
out, err = p.communicate()
out_str = out.decode("utf8", "replace")
err_str = err.decode("utf8", "replace")
return out_str, err_str, p.returncode
def check_help_output(pkg: str, subcommand: Sequence[str] | None = None) -> tuple[str, str]:
"""test that `python -m PKG [subcommand] -h` works"""
cmd = [sys.executable, "-m", pkg]
if subcommand:
cmd.extend(subcommand)
cmd.append("-h")
out, err, rc = get_output_error_code(cmd)
assert rc == 0, err
assert "Traceback" not in err
assert "Options" in out
assert "--help-all" in out
return out, err
def check_help_all_output(pkg: str, subcommand: Sequence[str] | None = None) -> tuple[str, str]:
"""test that `python -m PKG --help-all` works"""
cmd = [sys.executable, "-m", pkg]
if subcommand:
cmd.extend(subcommand)
cmd.append("--help-all")
out, err, rc = get_output_error_code(cmd)
assert rc == 0, err
assert "Traceback" not in err
assert "Options" in out
assert "Class options" in out
return out, err