Skip to content

Commit 2ba92a3

Browse files
committed
version info reading method updated, test updated
1 parent ace59c3 commit 2ba92a3

File tree

5 files changed

+108
-16
lines changed

5 files changed

+108
-16
lines changed

README.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
**CodeMage** is a tool that translates a source file written in one programming language into another language.
66
The translation will be done by Large Language Model AI(such as ChatGPT)
77

8-
## Release 0.1
8+
## Release 1.0.0
99

1010
### Features
1111

@@ -14,7 +14,54 @@ The translation will be done by Large Language Model AI(such as ChatGPT)
1414
3. Supported LLM model: openrouter, groq
1515
4. Default LLM model is openrouter(sao10k/l3-euryale-70b)
1616

17-
# Getting Started
17+
# Getting Started with `PyPI`
18+
19+
### 1. Download the package using PyPI
20+
```bash
21+
pip install code-mage
22+
```
23+
24+
### 2. Create your API_KEY at [openrouter](https://openrouter.ai/docs/api-keys) Or [Groq](https://console.groq.com/keys)
25+
26+
It's free with sign-up. You can easily sign-up with your google account
27+
28+
### 3.a Set-up the API_KEY using `Variable` (option 1)
29+
30+
```bash
31+
export API_KEY=YOUR-API-KEY
32+
```
33+
34+
### 3.b Set-up with `.toml` file (option 2)
35+
36+
With this option, you can also set other tool options.
37+
38+
- Start by creating a `.codemage-config.toml` in your home directory.
39+
40+
```bash
41+
mkdir ~/.codemage-config.toml
42+
```
43+
44+
- Add the following information to the file:
45+
46+
```toml
47+
model="groq" # if you wish to use OPEN ROUTER you can just delete this line
48+
GROQ_API_KEY="<YOUR-GROQ-API-KEY>"
49+
OPENROUTER_API_KEY="<YOUR-OPEN-ROUTER-API-KEY>"
50+
language="java" # you can use any of the supported languages
51+
stream=false # if you wish to get the output streamed, set it `true`
52+
token_usage=false # if you wish to get token_usage info, set it `true`
53+
output="result" # type any name for the output file without the extension
54+
```
55+
56+
### 4. Run the tool
57+
58+
```bash
59+
codemage <file-you-want-to-convert>
60+
# For example,
61+
codemage test.js
62+
```
63+
64+
# Getting Started by cloning the github repo
1865

1966
### 1. Install Python : https://www.python.org/downloads/
2067

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 = "release 0.1"
5+
VERSION = config.get("version")
66

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

code_mage/loadConfig.py

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

13+
config["version"] = __get_version_from_pyproject()
14+
1315
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 = "0.9.0"
3+
version = "1.0.0"
44
description = ""
55
authors = ["gitdevjin <[email protected]>"]
66
readme = "README.md"

tests/test_loadConfig.py

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,74 @@
11
import os
2-
from unittest.mock import patch
2+
from unittest.mock import patch, mock_open
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-
def test_load_config_file_exists(self, mock_toml_load, mock_os_exists):
10-
# Simulate that the file exists
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
1112
mock_os_exists.return_value = True
1213

13-
# Simulate the contents of the file
14-
mock_toml_load.return_value = {
15-
"language": "Python",
16-
"OPENROUTER_API_KEY": "mock_openrouter_api_key",
17-
}
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+
]
1822

1923
# Call load_config function
2024
config = load_config()
2125

2226
# Assertions
2327
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
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"}
28+
mock_file.assert_called_once_with("pyproject.toml", "r")
29+
assert config == {
30+
"language": "Python",
31+
"OPENROUTER_API_KEY": "mock_openrouter_api_key",
32+
"version": "0.9.0",
33+
}
2634

2735
@patch("os.path.exists")
28-
def test_load_config_file_not_exists(self, mock_os_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):
2939
# 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+
49+
config = load_config()
50+
51+
# Assertions
52+
mock_os_exists.assert_called_once_with(os.path.expanduser("~/.codemage-config.toml"))
53+
mock_file.assert_called_once_with("pyproject.toml", "r")
54+
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
3063
mock_os_exists.return_value = False
3164

65+
# Simulate the content of the pyproject.toml file
66+
mock_toml_load.return_value = {"tool": {"poetry": {"version": "0.9.0"}}}
67+
3268
# Call the function under test
3369
config = load_config()
3470

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

0 commit comments

Comments
 (0)