Skip to content

Commit bdf5635

Browse files
authored
Merge pull request #19 from ilyas829/update_4
Update 4
2 parents 28ef13c + dc13b7a commit bdf5635

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
openai>=1.0.0
1+
openai>=1.51.0
22
pathlib2>=2.3.7; python_version < "3.4"
3+
pytest>=8.3.0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
from pathlib import Path
3+
import pytest
4+
5+
from code_generator import _safe_filename, save_output
6+
7+
8+
@pytest.mark.parametrize(
9+
"program_name,language,expected",
10+
[
11+
("Two Sum", "python", "two_sum_in_python.txt"),
12+
("Hello-World!", "JS", "hello-world_in_js.txt"),
13+
(" Weird Name ", "Go", "weird___name_in_go.txt"),
14+
("", "rust", "generated_code_in_rust.txt"),
15+
],
16+
)
17+
def test_safe_filename(program_name, language, expected):
18+
assert _safe_filename(program_name, language) == expected
19+
20+
21+
def test_save_output_writes_file(tmp_path: Path):
22+
# Change CWD to temporary directory to avoid polluting repo
23+
cwd = os.getcwd()
24+
os.chdir(tmp_path)
25+
try:
26+
program = "My App"
27+
lang = "Python"
28+
content = "print('hello')\n"
29+
out_path = save_output(program, lang, content)
30+
31+
# Ensure path is inside output dir and file exists
32+
assert Path(out_path).exists()
33+
assert Path(out_path).parent.name == "output"
34+
assert Path(out_path).read_text(encoding="utf-8") == content
35+
finally:
36+
os.chdir(cwd)
37+
38+

0 commit comments

Comments
 (0)