Skip to content

Commit 1a5942b

Browse files
committed
un comment version test to see whats wrong we are halfway through fixing these tests we dont stop
1 parent fc5b402 commit 1a5942b

File tree

1 file changed

+72
-72
lines changed

1 file changed

+72
-72
lines changed

tests/cli/commands/test_version.py

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,93 @@
1-
# import pytest
2-
# import os
3-
# from unittest.mock import patch, mock_open, MagicMock
4-
# from typer.testing import CliRunner
1+
import pytest
2+
import os
3+
from unittest.mock import patch, mock_open, MagicMock
4+
from typer.testing import CliRunner
55

6-
# # Assuming cli.main is the entry point for typer app
7-
# # We need to adjust imports based on actual structure if main.py is elsewhere
8-
# # Let's assume main.py exists and imports version_command correctly
9-
# # We will test the command function directly for simplicity here,
10-
# # avoiding the need for a full typer app setup in this unit test.
11-
# from cli.commands.version import version_command
6+
# Assuming cli.main is the entry point for typer app
7+
# We need to adjust imports based on actual structure if main.py is elsewhere
8+
# Let's assume main.py exists and imports version_command correctly
9+
# We will test the command function directly for simplicity here,
10+
# avoiding the need for a full typer app setup in this unit test.
11+
from cli.commands.version import version_command
1212

13-
# # Dummy translation messages
14-
# DUMMY_MESSAGES = {
15-
# "version_info": "SpiceCode Version:",
16-
# "version_not_found": "Version information not found in setup.py",
17-
# "setup_not_found": "Error: setup.py not found.",
18-
# "error": "Error:",
19-
# }
13+
# Dummy translation messages
14+
DUMMY_MESSAGES = {
15+
"version_info": "SpiceCode Version:",
16+
"version_not_found": "Version information not found in setup.py",
17+
"setup_not_found": "Error: setup.py not found.",
18+
"error": "Error:",
19+
}
2020

21-
# # Mock CURRENT_DIR (assuming it's the 'cli' directory for the command)
22-
# TEST_CURRENT_DIR = "/home/ubuntu/spicecode/cli"
23-
# EXPECTED_SETUP_PATH = "/home/ubuntu/spicecode/setup.py"
21+
# Mock CURRENT_DIR (assuming it's the 'cli' directory for the command)
22+
TEST_CURRENT_DIR = "/home/ubuntu/spicecode/cli"
23+
EXPECTED_SETUP_PATH = "/home/ubuntu/spicecode/setup.py"
2424

25-
# @patch("cli.commands.version.get_translation")
26-
# @patch("os.path.exists")
27-
# @patch("builtins.open", new_callable=mock_open)
28-
# def test_version_command_success(mock_file_open, mock_exists, mock_get_translation, capsys):
29-
# """Test version command when setup.py exists and contains version."""
30-
# mock_get_translation.return_value = DUMMY_MESSAGES
31-
# mock_exists.return_value = True
32-
# mock_file_open.read_data = "version=\"1.2.3\",\n" # Simulate setup.py content
33-
# mock_file_open.return_value.read.return_value = mock_file_open.read_data
34-
# mock_file_open.return_value.__iter__.return_value = mock_file_open.read_data.splitlines()
25+
@patch("cli.commands.version.get_translation")
26+
@patch("os.path.exists")
27+
@patch("builtins.open", new_callable=mock_open)
28+
def test_version_command_success(mock_file_open, mock_exists, mock_get_translation, capsys):
29+
"""Test version command when setup.py exists and contains version."""
30+
mock_get_translation.return_value = DUMMY_MESSAGES
31+
mock_exists.return_value = True
32+
mock_file_open.read_data = "version=\"1.2.3\",\n" # Simulate setup.py content
33+
mock_file_open.return_value.read.return_value = mock_file_open.read_data
34+
mock_file_open.return_value.__iter__.return_value = mock_file_open.read_data.splitlines()
3535

36-
# version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
36+
version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
3737

38-
# captured = capsys.readouterr()
38+
captured = capsys.readouterr()
3939

40-
# mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
41-
# mock_file_open.assert_called_once_with(EXPECTED_SETUP_PATH, "r")
42-
# assert "SpiceCode Version: 1.2.3" in captured.out
40+
mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
41+
mock_file_open.assert_called_once_with(EXPECTED_SETUP_PATH, "r")
42+
assert "SpiceCode Version: 1.2.3" in captured.out
4343

44-
# @patch("cli.commands.version.get_translation")
45-
# @patch("os.path.exists")
46-
# @patch("builtins.open", new_callable=mock_open)
47-
# def test_version_command_version_not_in_setup(mock_file_open, mock_exists, mock_get_translation, capsys):
48-
# """Test version command when setup.py exists but lacks version info."""
49-
# mock_get_translation.return_value = DUMMY_MESSAGES
50-
# mock_exists.return_value = True
51-
# mock_file_open.read_data = "name=\"spicecode\"\n" # Simulate setup.py without version
52-
# mock_file_open.return_value.read.return_value = mock_file_open.read_data
53-
# mock_file_open.return_value.__iter__.return_value = mock_file_open.read_data.splitlines()
44+
@patch("cli.commands.version.get_translation")
45+
@patch("os.path.exists")
46+
@patch("builtins.open", new_callable=mock_open)
47+
def test_version_command_version_not_in_setup(mock_file_open, mock_exists, mock_get_translation, capsys):
48+
"""Test version command when setup.py exists but lacks version info."""
49+
mock_get_translation.return_value = DUMMY_MESSAGES
50+
mock_exists.return_value = True
51+
mock_file_open.read_data = "name=\"spicecode\"\n" # Simulate setup.py without version
52+
mock_file_open.return_value.read.return_value = mock_file_open.read_data
53+
mock_file_open.return_value.__iter__.return_value = mock_file_open.read_data.splitlines()
5454

55-
# version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
55+
version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
5656

57-
# captured = capsys.readouterr()
57+
captured = capsys.readouterr()
5858

59-
# mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
60-
# mock_file_open.assert_called_once_with(EXPECTED_SETUP_PATH, "r")
61-
# assert "Version information not found in setup.py" in captured.out
59+
mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
60+
mock_file_open.assert_called_once_with(EXPECTED_SETUP_PATH, "r")
61+
assert "Version information not found in setup.py" in captured.out
6262

63-
# @patch("cli.commands.version.get_translation")
64-
# @patch("os.path.exists")
65-
# def test_version_command_setup_not_found(mock_exists, mock_get_translation, capsys):
66-
# """Test version command when setup.py does not exist."""
67-
# mock_get_translation.return_value = DUMMY_MESSAGES
68-
# mock_exists.return_value = False
63+
@patch("cli.commands.version.get_translation")
64+
@patch("os.path.exists")
65+
def test_version_command_setup_not_found(mock_exists, mock_get_translation, capsys):
66+
"""Test version command when setup.py does not exist."""
67+
mock_get_translation.return_value = DUMMY_MESSAGES
68+
mock_exists.return_value = False
6969

70-
# version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
70+
version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
7171

72-
# captured = capsys.readouterr()
72+
captured = capsys.readouterr()
7373

74-
# mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
75-
# assert "Error: setup.py not found." in captured.out
74+
mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
75+
assert "Error: setup.py not found." in captured.out
7676

77-
# @patch("cli.commands.version.get_translation")
78-
# @patch("os.path.exists")
79-
# @patch("builtins.open", side_effect=OSError("Permission denied"))
80-
# def test_version_command_read_error(mock_file_open, mock_exists, mock_get_translation, capsys):
81-
# """Test version command handles exceptions during file reading."""
82-
# mock_get_translation.return_value = DUMMY_MESSAGES
83-
# mock_exists.return_value = True
77+
@patch("cli.commands.version.get_translation")
78+
@patch("os.path.exists")
79+
@patch("builtins.open", side_effect=OSError("Permission denied"))
80+
def test_version_command_read_error(mock_file_open, mock_exists, mock_get_translation, capsys):
81+
"""Test version command handles exceptions during file reading."""
82+
mock_get_translation.return_value = DUMMY_MESSAGES
83+
mock_exists.return_value = True
8484

85-
# version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
85+
version_command(LANG_FILE="dummy_lang.txt", CURRENT_DIR=TEST_CURRENT_DIR)
8686

87-
# captured = capsys.readouterr()
87+
captured = capsys.readouterr()
8888

89-
# mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
90-
# mock_file_open.assert_called_once_with(EXPECTED_SETUP_PATH, "r")
91-
# assert "Error: Permission denied" in captured.out
89+
mock_exists.assert_called_once_with(EXPECTED_SETUP_PATH)
90+
mock_file_open.assert_called_once_with(EXPECTED_SETUP_PATH, "r")
91+
assert "Error: Permission denied" in captured.out
9292

9393

0 commit comments

Comments
 (0)