Skip to content

Tighten assertions in test_shim_include_override_additional_import to avoid false positives #360

Description

@coderabbitai

Summary

The test test_shim_include_override_additional_import in numbast/src/numbast/experimental/mlir/tools/tests/test_shim_include_override.py has two weak assertions that can produce false positives:

  1. os_is_imported is set to True for any line starting with "import", not specifically import os. Other generated imports could satisfy this check even if os was never imported.
  2. shim_include line is never required to be present — the test only asserts "os" in line if such a line is found, but never fails if no shim_include line is emitted at all. This means the shim include override behavior could be silently broken.

Proposed Fix

  • Change the import check to detect specifically import os (e.g., line.strip() == "import os" or line.strip().startswith("from os import")).
  • Introduce a shim_include_found flag and assert it is True after the loop, so the test fails if the shim include override line is not emitted.

References

Requested by @isVoid.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions