77 validate_library_name ,
88)
99
10+
1011def test_find_cargo_toml_exists (tmp_path , mock_os_path_exists ):
1112 (tmp_path / "Cargo.toml" ).touch ()
1213 mock_os_path_exists .return_value = True
1314 result = find_cargo_toml (str (tmp_path ))
1415 assert result == str (tmp_path / "Cargo.toml" )
1516
17+
1618def test_find_cargo_toml_not_found ():
1719 result = find_cargo_toml ()
1820 assert result is None
1921
22+
2023def test_validate_library_name_valid ():
2124 assert validate_library_name ("serde" ) is True
2225
26+
2327def test_validate_library_name_invalid (capsys ):
2428 assert validate_library_name ("serde;malicious" ) is False
2529 captured = capsys .readouterr ()
2630 assert "Invalid library name: serde;malicious" in captured .out
2731
32+
2833def test_check_cargo_installed (mock_shutil_which , capsys ):
2934 mock_shutil_which .return_value = "/usr/bin/cargo"
3035 assert check_cargo_installed () is True
@@ -34,24 +39,30 @@ def test_check_cargo_installed(mock_shutil_which, capsys):
3439 captured = capsys .readouterr ()
3540 assert "cargo is not installed or not found in PATH" in captured .out
3641
37- def test_cargo_install_success (tmp_path , mock_subprocess_run , mock_os_chdir , capsys ):
42+
43+ def test_cargo_install_success (tmp_path , mock_subprocess_run , mock_os_chdir , capsys ):
3844 (tmp_path / "Cargo.toml" ).touch ()
39- mock_subprocess_run .return_value = MagicMock (returncode = 0 , stdout = "Added serde" , stderr = "" )
45+ mock_subprocess_run .return_value = MagicMock (
46+ returncode = 0 , stdout = "Added serde" , stderr = ""
47+ )
4048 cargo_install (["serde" ])
4149 captured = capsys .readouterr ()
4250 assert "Running cargo add serde ..." in captured .out
4351 assert "Cargo output:\n Added serde" in captured .out
4452 mock_os_chdir .assert_called ()
4553
46- def test_cargo_install_failure (tmp_path , mock_subprocess_run , capsys ):
54+
55+ def test_cargo_install_failure (tmp_path , mock_subprocess_run , capsys ):
4756 (tmp_path / "Cargo.toml" ).touch ()
4857 mock_subprocess_run .side_effect = subprocess .CalledProcessError (
49- returncode = 1 , cmd = ["cargo" , "add" , "serde" ], output = "" , stderr = "Error: invalid crate"
58+ returncode = 1 ,
59+ cmd = ["cargo" , "add" , "serde" ],
60+ output = "" ,
61+ stderr = "Error: invalid crate" ,
5062 )
5163 cargo_install (["serde" ])
5264 captured = capsys .readouterr ()
5365 if "Failed to install serde" not in captured .out :
5466 raise AssertionError
5567 if "stderr:\n Error: invalid crate" not in captured .out :
5668 raise AssertionError
57-
0 commit comments