-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af036d1
commit 91cfd07
Showing
8 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
testpaths = tests | ||
python_files = test_*.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ chardet | |
colorama | ||
halo | ||
pathspec | ||
pre-commit | ||
pytest | ||
pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pytest | ||
from repopack.config import load_config, merge_configs, DEFAULT_CONFIG | ||
from repopack.exceptions import ConfigurationError | ||
|
||
|
||
def test_load_config(tmp_path): | ||
config_file = tmp_path / "config.json" | ||
config_file.write_text('{"output": {"file_path": "custom_output.txt"}}') | ||
|
||
config = load_config(str(config_file)) | ||
assert config["output"]["file_path"] == "custom_output.txt" | ||
|
||
|
||
def test_load_config_invalid_json(tmp_path): | ||
config_file = tmp_path / "invalid_config.json" | ||
config_file.write_text('{"output": {') | ||
|
||
with pytest.raises(ConfigurationError): | ||
load_config(str(config_file)) | ||
|
||
|
||
def test_merge_configs(): | ||
file_config = {"output": {"file_path": "file_output.txt"}} | ||
cli_config = {"output": {"show_line_numbers": True}} | ||
merged = merge_configs(file_config, cli_config) | ||
|
||
assert merged["output"]["file_path"] == "file_output.txt" | ||
assert merged["output"]["show_line_numbers"] == True | ||
assert merged["output"]["style"] == DEFAULT_CONFIG["output"]["style"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from unittest.mock import patch, mock_open | ||
from repopack.utils.file_handler import is_binary, sanitize_file | ||
|
||
|
||
def test_is_binary(): | ||
with patch("builtins.open", mock_open(read_data=b"\x00\x01\x02\x03")): | ||
assert is_binary("fake_binary_file") | ||
|
||
|
||
def test_is_not_binary(): | ||
with patch("builtins.open", mock_open(read_data="Hello, World!")): | ||
assert not is_binary("fake_text_file") | ||
|
||
|
||
def test_sanitize_file(): | ||
config = { | ||
"output": {"remove_comments": False, "remove_empty_lines": True, "show_line_numbers": True} | ||
} | ||
content = "Line 1\n\nLine 3\n" | ||
expected = "1 | Line 1\n2 | Line 3" | ||
|
||
with patch("builtins.open", mock_open(read_data=content.encode())): | ||
result = sanitize_file("fake_file.txt", config) | ||
|
||
assert result == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from unittest.mock import patch | ||
from repopack.utils.ignore_utils import ( | ||
get_ignore_patterns, | ||
get_all_ignore_patterns, | ||
create_ignore_filter, | ||
) | ||
|
||
|
||
def test_get_ignore_patterns(tmp_path): | ||
ignore_file = tmp_path / ".gitignore" | ||
ignore_file.write_text("*.log\n#comment\nnode_modules/") | ||
|
||
patterns = get_ignore_patterns(".gitignore", str(tmp_path)) | ||
assert patterns == ["*.log", "node_modules/"] | ||
|
||
|
||
def test_get_all_ignore_patterns(): | ||
config = { | ||
"ignore": { | ||
"use_default_patterns": True, | ||
"use_gitignore": True, | ||
"custom_patterns": ["*.custom"], | ||
} | ||
} | ||
with patch("repopack.utils.ignore_utils.get_ignore_patterns", return_value=["*.gitignore"]): | ||
patterns = get_all_ignore_patterns("/fake/path", config) | ||
|
||
assert "*.log" in patterns # from DEFAULT_IGNORE_LIST | ||
assert "*.gitignore" in patterns # from mocked .gitignore | ||
assert "*.custom" in patterns # from custom patterns | ||
|
||
|
||
def test_create_ignore_filter(): | ||
patterns = ["*.log", "node_modules/"] | ||
ignore_filter = create_ignore_filter(patterns) | ||
|
||
assert not ignore_filter("test.log") | ||
assert not ignore_filter("node_modules/package.json") | ||
assert ignore_filter("src/main.py") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from repopack.utils.tree_generator import generate_tree_string | ||
|
||
|
||
def test_generate_tree_string(): | ||
files = ["src/main.py", "src/utils/helper.py", "tests/test_main.py", "README.md"] | ||
expected = ( | ||
"README.md\n" | ||
"src/\n" | ||
" main.py\n" | ||
" utils/\n" | ||
" helper.py\n" | ||
"tests/\n" | ||
" test_main.py" | ||
) | ||
result = generate_tree_string(files) | ||
assert result == expected |