Skip to content
Open
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
Empty file added tests/__init__.py
Empty file.
43 changes: 43 additions & 0 deletions tests/test_diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Tests for build diagnostic metadata generation"""
import sys, os, json, tempfile, unittest

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove unused imports.

The imports os, json, and tempfile are never used in this test file.

🧹 Proposed fix to remove unused imports
-import sys, os, json, tempfile, unittest
+import sys, unittest
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import sys, os, json, tempfile, unittest
import sys, unittest
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_diagnostics.py` at line 2, Remove the unused imports os, json, and
tempfile from the import statement on the first line. Keep only the imports that
are actually used in the test file, which are sys and unittest. Update the
import statement to include only the necessary dependencies.

from pathlib import Path

_REPO = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(_REPO))

try:
from build import build_diagnostic_report, write_diagnostic_report
HAS_BUILD = True
except ImportError:
HAS_BUILD = False
Comment on lines +8 to +12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if build_diagnostic_report and write_diagnostic_report exist in build.py

# Search for function definitions
ast-grep outline build.py --match 'build_diagnostic_report|write_diagnostic_report' --view expanded

Repository: jackjin1997/TentOfTrials

Length of output: 185


🏁 Script executed:

#!/bin/bash
# Find build.py to verify its location and content
find . -name "build.py" -o -name "build" -type d | head -20

Repository: jackjin1997/TentOfTrials

Length of output: 173


🏁 Script executed:

#!/bin/bash
# List files in the repository root to understand structure
git ls-files | head -30

Repository: jackjin1997/TentOfTrials

Length of output: 1043


🏁 Script executed:

#!/bin/bash
# Check the actual test file to see what's being tested
cat -n tests/test_diagnostics.py | head -30

Repository: jackjin1997/TentOfTrials

Length of output: 1473


🏁 Script executed:

#!/bin/bash
# Read the build.py file to see what functions are actually defined
wc -l build.py

Repository: jackjin1997/TentOfTrials

Length of output: 175


🏁 Script executed:

#!/bin/bash
# Check what functions/classes are defined in build.py
ast-grep outline build.py --view expanded

Repository: jackjin1997/TentOfTrials

Length of output: 1784


🏁 Script executed:

#!/bin/bash
# Search for any mention of build_diagnostic_report or write_diagnostic_report in build.py
rg "build_diagnostic_report|write_diagnostic_report" build.py

Repository: jackjin1997/TentOfTrials

Length of output: 162


🏁 Script executed:

#!/bin/bash
# Check the entire test file to see all test methods and verify write_diagnostic_report usage
cat -n tests/test_diagnostics.py

Repository: jackjin1997/TentOfTrials

Length of output: 2119


🏁 Script executed:

#!/bin/bash
# Verify there are no other references to write_diagnostic_report in the test file
rg "write_diagnostic_report" tests/test_diagnostics.py

Repository: jackjin1997/TentOfTrials

Length of output: 233


Remove non-existent imports and implement missing functions or skip file.

The test imports build_diagnostic_report and write_diagnostic_report from build.py, but neither function exists in that module. This causes the ImportError to be caught (lines 11-12), setting HAS_BUILD = False, which causes all four test methods to skip unconditionally. Additionally, write_diagnostic_report is imported but never used.

Either:

  1. Implement these functions in build.py, or
  2. Remove the import and the test file if it's not yet ready
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_diagnostics.py` around lines 8 - 12, The try-except block is
importing `build_diagnostic_report` and `write_diagnostic_report` from the build
module, but these functions do not exist in build.py, causing the ImportError to
be silently caught and setting HAS_BUILD to False, which causes all test methods
to skip unconditionally. Either implement both the `build_diagnostic_report` and
`write_diagnostic_report` functions in the build.py module to match what the
tests expect, or remove this import block entirely and refactor the test file to
not depend on these non-existent functions if the tests are not yet ready to be
implemented.


class TestDiagnosticMetadata(unittest.TestCase):
def test_report_has_required_fields(self):
if not HAS_BUILD: self.skipTest("build.py not importable")
r = build_diagnostic_report([("test", True, 1.0, "ok", None)], "abc123")
for key in ["generated_at", "commit", "total_modules", "passed", "failed", "modules"]:
self.assertIn(key, r)

def test_report_counts_pass_fail(self):
if not HAS_BUILD: self.skipTest("build.py not importable")
r = build_diagnostic_report([
("a", True, 1.0, "ok", None),
("b", False, 2.0, "fail", None),
], "abc123")
self.assertEqual(r["passed"], 1)
self.assertEqual(r["failed"], 1)
self.assertEqual(r["total_modules"], 2)

def test_report_module_status(self):
if not HAS_BUILD: self.skipTest("build.py not importable")
r = build_diagnostic_report([("test", True, 1.0, "ok", None)], "abc123")
self.assertEqual(r["modules"][0]["status"], "PASS")
self.assertIn("elapsed_seconds", r["modules"][0])

def test_empty_results(self):
if not HAS_BUILD: self.skipTest("build.py not importable")
r = build_diagnostic_report([], "abc123")
self.assertEqual(r["total_modules"], 0)

if __name__ == "__main__":
unittest.main()