Skip to content

test: add failing tests covering all identified quality issues - #25

Open
bjinwright wants to merge 6 commits into
masterfrom
claude/code-quality-review-vyiu5
Open

bjinwright wants to merge 6 commits into
masterfrom
claude/code-quality-review-vyiu5

Conversation

@bjinwright

Copy link
Copy Markdown
Member

Red phase for TDD cycle. Tests cover:

  • C1: check_envs raises for falsy-but-set env vars (if not value: bug)
  • C2: list_envs_module leaves partial file on import failure
  • M1: import_mod permanently mutates sys.path on failed import
  • M5: check_envs skips file cleanup when exception is raised
  • n2: VAR_TYPES is a live dict_keys view instead of stable tuple
  • n4: package missing version

Also: remove Python 2 mock compat shim, add tearDown for env var
isolation, remove unused 'vm' context-manager variables, fix
test_list_envs NameError (CliRunner and cli envs were never in scope).

https://claude.ai/code/session_014GRVQn5ZU9SAce5eLb88qz

claude added 6 commits May 24, 2026 18:22
Red phase for TDD cycle. Tests cover:
- C1: check_envs raises for falsy-but-set env vars (if not value: bug)
- C2: list_envs_module leaves partial file on import failure
- M1: import_mod permanently mutates sys.path on failed import
- M5: check_envs skips file cleanup when exception is raised
- n2: VAR_TYPES is a live dict_keys view instead of stable tuple
- n4: package missing __version__

Also: remove Python 2 mock compat shim, add tearDown for env var
isolation, remove unused 'vm' context-manager variables, fix
test_list_envs NameError (CliRunner and cli envs were never in scope).

https://claude.ai/code/session_014GRVQn5ZU9SAce5eLb88qz
Critical:
- C1 (cli.py): replace `if not value:` with `if value is None:` in
  check_envs — env vars set to 0, False, or [] were incorrectly
  reported as unset
- C2 (util.py): wrap import_mod in try/except in list_envs_module so
  the partial temp file is always cleaned up on import failure

Major:
- M1 (util.py): restore sys.path when both import attempts fail in
  import_mod, preventing permanent mutation of the module search path
- M2 (setup.py): use context manager in parse_requirements to close
  the file handle after reading
- M3 (util.py, cli.py): remove Python 2 dead code — raw_input shim,
  duplicate sys.version_info branches in import_mod, and try/except
  mock import compat in tests
- M4 (util.py): fix convert_module falsy-default bug; `if not
  default_val: default_val = v` was overwriting valid falsy user input
  (0, False, "") — replaced with `ast.literal_eval(raw) if raw else v`
- M5 (cli.py): wrap check_envs loop in try/finally so the result file
  is always removed, even when EnvsValueException is raised

Minor:
- m1 (__init__.py): remove unused _envs_list = [] dead variable
- m2 (__init__.py): replace `not var_type in .keys()` with
  `var_type not in self.valid_types`
- m3 (tests.py): add tearDown to remove env vars set in setUp,
  preventing state bleed between test runs
- m4 (__init__.py): use pid-based ENVS_RESULT_FILENAME to eliminate
  race conditions between concurrent processes / test runs
- m5 (setup.py): add python_requires='>=3.6'

Nit:
- n1 (__init__.py, util.py): add type hints to public API
- n2 (util.py): freeze VAR_TYPES as tuple() instead of live dict_keys
- n3 (tests.py): remove unused `as vm` in assertRaises calls
- n4 (__init__.py, setup.py): add __version__ = '1.3'; setup.py reads
  it via regex instead of duplicating the string
- n5 (all): replace .format() calls with f-strings throughout

https://claude.ai/code/session_014GRVQn5ZU9SAce5eLb88qz
- Add .github/workflows/tests.yml: matrix across Python 3.8–3.12,
  uses actions/checkout@v4 and actions/setup-python@v5, sets
  PYTHONPATH so the package is importable without editable install,
  runs pytest with --tb=short
- Update test-requirements.txt: drop nose==1.3.7, coverage==4.2, and
  mock (stdlib since Python 3.3); add pytest>=7.0 and pytest-cov;
  bump click floor to >=8.0 to match the existing codebase

https://claude.ai/code/session_014GRVQn5ZU9SAce5eLb88qz
Added UtilTestCase covering previously untested util.py paths:
- test_import_util_returns_correct_callable (lines 14-16)
- test_import_util_returns_module_level_value
- test_convert_module_skips_lowercase_attributes (lines 20-23)
- test_convert_module_convert_false_produces_minimal_dict
- test_convert_module_convert_true_with_explicit_default (lines 25-33)
- test_convert_module_empty_default_falls_back_to_original (line 27 else)
- test_convert_module_invalid_var_type_raises (lines 31-32)

Added CLICommandTestCase covering previously untested cli.py paths:
- test_list_envs_removes_result_file_by_default (line 51 — delete branch
  never hit because existing test always passed --keep-result True)
- test_convert_settings_writes_output_file (lines 25-33 — entire
  convert-settings command was untested)
- test_convert_settings_raises_on_empty_filename (lines 29-30)

Added .coveragerc to exclude test_settings*.py fixture files from
the coverage report (they are test helpers, not source modules).

Coverage before: __init__.py 100%, cli.py 80%, util.py 65%, total 90%
Coverage after:  all source modules 100%, total 99%

https://claude.ai/code/session_014GRVQn5ZU9SAce5eLb88qz
Runs on Python 3.12 only (separate from the 5-version compatibility
matrix). Uses --cov-fail-under=95 so the job fails if coverage drops
below that floor.

https://claude.ai/code/session_014GRVQn5ZU9SAce5eLb88qz

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants