MCPcopy Create free account
hub / github.com/idank/explainshell / TestAtFileExpansion

Class TestAtFileExpansion

tests/test_manager.py:2499–2626  ·  view source on GitHub ↗

Tests that @file arguments are expanded through the CLI.

Source from the content-addressed store, hash-verified

2497
2498
2499class TestAtFileExpansion(unittest.TestCase):
2500 """Tests that @file arguments are expanded through the CLI."""
2501
2502 @patch("explainshell.extraction.common.gz_sha256", side_effect=lambda p: p)
2503 @patch("os.path.islink", return_value=False)
2504 @patch(
2505 "explainshell.manager.config.source_from_path",
2506 side_effect=lambda p: f"fake/release/1/{os.path.basename(p)}",
2507 )
2508 def test_extract_expands_at_file(
2509 self,
2510 _mock_source: MagicMock,
2511 _mock_link: MagicMock,
2512 _mock_sha: MagicMock,
2513 ) -> None:
2514 """@file arg is expanded to the file's contents and reaches the classifier."""
2515 with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f:
2516 f.write("/fake/echo.1.gz\n")
2517 f.flush()
2518 list_path = f.name
2519
2520 try:
2521 with _temp_db() as db_path:
2522 Store.create(db_path).close()
2523 runner = CliRunner()
2524 with self.assertLogs("explainshell.manager", level="INFO") as cm:
2525 result = runner.invoke(
2526 cli,
2527 [
2528 "--db",
2529 db_path,
2530 "extract",
2531 "--mode",
2532 "llm:test-model",
2533 "--dry-run",
2534 f"@{list_path}",
2535 ],
2536 )
2537
2538 self.assertEqual(result.exit_code, 0, result.output)
2539 self.assertIn("fake/release/1/echo.1.gz", "\n".join(cm.output))
2540 finally:
2541 os.unlink(list_path)
2542
2543 @patch("explainshell.extraction.common.gz_sha256", side_effect=lambda p: p)
2544 @patch("os.path.islink", return_value=False)
2545 @patch(
2546 "explainshell.manager.config.source_from_path",
2547 side_effect=lambda p: f"fake/release/1/{os.path.basename(p)}",
2548 )
2549 def test_extract_at_file_skips_blanks_and_comments(
2550 self,
2551 _mock_source: MagicMock,
2552 _mock_link: MagicMock,
2553 _mock_sha: MagicMock,
2554 ) -> None:
2555 with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as f:
2556 f.write("/fake/echo.1.gz\n\n# comment\n \n")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected