Skip to content

Commit 46a14cf

Browse files
committed
README.md file updated, test bug fixed
1 parent 2ba92a3 commit 46a14cf

File tree

4 files changed

+14
-59
lines changed

4 files changed

+14
-59
lines changed

code_mage/argsParser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def arg_parser(config):
5-
VERSION = config.get("version")
5+
VERSION = "1.1.1"
66

77
parser = argparse.ArgumentParser(
88
description="This Tool translates a source file into another programming language."

code_mage/loadConfig.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,4 @@ def load_config():
1010
else:
1111
config = {}
1212

13-
config["version"] = __get_version_from_pyproject()
14-
1513
return config
16-
17-
18-
def __get_version_from_pyproject():
19-
with open("pyproject.toml", "r") as f:
20-
pyproject_data = toml.load(f)
21-
return pyproject_data["tool"]["poetry"]["version"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "code-mage"
3-
version = "1.0.0"
3+
version = "1.1.1"
44
description = ""
55
authors = ["gitdevjin <[email protected]>"]
66
readme = "README.md"

tests/test_loadConfig.py

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,37 @@
11
import os
2-
from unittest.mock import patch, mock_open
2+
from unittest.mock import patch
33
from code_mage.loadConfig import load_config # Adjust the import path accordingly
44

55

66
class TestLoadConfig:
77
@patch("os.path.exists")
88
@patch("toml.load")
9-
@patch("builtins.open", new_callable=mock_open)
10-
def test_load_config_file_exists(self, mock_file, mock_toml_load, mock_os_exists):
11-
# Simulate that the config file exists
9+
def test_load_config_file_exists(self, mock_toml_load, mock_os_exists):
10+
# Simulate that the file exists
1211
mock_os_exists.return_value = True
1312

14-
# Simulate the contents of the config file
15-
mock_toml_load.side_effect = [
16-
{
17-
"language": "Python",
18-
"OPENROUTER_API_KEY": "mock_openrouter_api_key",
19-
}, # First call (config file)
20-
{"tool": {"poetry": {"version": "0.9.0"}}}, # Second call (pyproject.toml)
21-
]
22-
23-
# Call load_config function
24-
config = load_config()
25-
26-
# Assertions
27-
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
28-
mock_file.assert_called_once_with("pyproject.toml", "r")
29-
assert config == {
13+
# Simulate the contents of the file
14+
mock_toml_load.return_value = {
3015
"language": "Python",
3116
"OPENROUTER_API_KEY": "mock_openrouter_api_key",
32-
"version": "0.9.0",
3317
}
3418

35-
@patch("os.path.exists")
36-
@patch("toml.load")
37-
@patch("builtins.open", new_callable=mock_open)
38-
def test_load_config_file_with_no_content(self, mock_file, mock_toml_load, mock_os_exists):
39-
# Simulate that the file does not exist
40-
mock_os_exists.return_value = True
41-
42-
# Call the function under test
43-
44-
mock_toml_load.side_effect = [
45-
{},
46-
{"tool": {"poetry": {"version": "0.9.0"}}}, # Second call (pyproject.toml)
47-
]
48-
19+
# Call load_config function
4920
config = load_config()
5021

5122
# Assertions
5223
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
53-
mock_file.assert_called_once_with("pyproject.toml", "r")
24+
mock_toml_load.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
25+
assert config == {"language": "Python", "OPENROUTER_API_KEY": "mock_openrouter_api_key"}
5426

55-
# Assert the default config with version added
56-
assert config == {"version": "0.9.0"}
57-
58-
@patch("os.path.exists") # Third argument
59-
@patch("builtins.open") # Second argument
60-
@patch("toml.load") # First argument
61-
def test_load_config_file_not_exists(self, mock_toml_load, mock_file, mock_os_exists):
62-
# Simulate that the config file does not exist
27+
@patch("os.path.exists")
28+
def test_load_config_file_not_exists(self, mock_os_exists):
29+
# Simulate that the file does not exist
6330
mock_os_exists.return_value = False
6431

65-
# Simulate the content of the pyproject.toml file
66-
mock_toml_load.return_value = {"tool": {"poetry": {"version": "0.9.0"}}}
67-
6832
# Call the function under test
6933
config = load_config()
7034

7135
# Assertions
7236
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
73-
mock_file.assert_called_once_with("pyproject.toml", "r")
74-
assert config == {"version": "0.9.0"}
37+
assert config == {}

0 commit comments

Comments
 (0)