feat: Introduce executable build for Onyx CLI, add its source, and implement new tests.
This commit is contained in:
1 parent
e498031f10
commit
af43694c98
33 files changed
+862
-22978
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
sys.path.append(str(Path("src").resolve()))
|
||||
from click.testing import CliRunner
|
||||
from onyx import cli
|
||||
import os
|
||||
|
||||
# Setup test vault
|
||||
vault_path = Path("test_vault_newline").resolve()
|
||||
if vault_path.exists():
|
||||
import shutil
|
||||
shutil.rmtree(vault_path)
|
||||
vault_path.mkdir(exist_ok=True)
|
||||
|
||||
# Create config
|
||||
config_dir = Path(".onyx-cli-test")
|
||||
config_dir.mkdir(exist_ok=True)
|
||||
config_file = config_dir / "config.yaml"
|
||||
config_file.write_text(f"default_vault: test\nvaults:\n test: {str(vault_path).replace(os.sep, '/')}", encoding="utf-8")
|
||||
|
||||
# Mock the config path in OnyxCLI (we need to monkeypatch or just rely on the fact that we can't easily change the class attribute globally without reloading,
|
||||
# but wait, OnyxCLI is instantiated inside the commands.
|
||||
# I'll just monkeypatch OnyxCLI.__init__ to use my config file for this test, or better, just set the env var if supported?
|
||||
# The code uses Path.home() / '.onyx-cli' / 'config.yaml'.
|
||||
# I'll monkeypatch Path.home to return my local dir.
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
with patch("pathlib.Path.home", return_value=Path.cwd() / "test_home"):
|
||||
# Setup home dir
|
||||
home = Path.cwd() / "test_home"
|
||||
(home / ".onyx-cli").mkdir(parents=True, exist_ok=True)
|
||||
(home / ".onyx-cli" / "config.yaml").write_text(f"default_vault: test\nvaults:\n test: {str(vault_path).replace(os.sep, '/')}", encoding="utf-8")
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
print("--- Testing with literal \\n ---")
|
||||
result = runner.invoke(cli, ['create', 'newline_test', '--content', 'Line1\\nLine2', '--vault', 'test'])
|
||||
|
||||
if result.exit_code != 0:
|
||||
print(f"Command failed: {result.output}")
|
||||
else:
|
||||
note_path = vault_path / "newline_test.md"
|
||||
if note_path.exists():
|
||||
content = note_path.read_text(encoding='utf-8-sig')
|
||||
print(f"Content length: {len(content)}")
|
||||
print(f"Content repr: {repr(content)}")
|
||||
if '\n' in content and '\\n' not in content:
|
||||
print("Result: Real newline found")
|
||||
elif '\\n' in content:
|
||||
print("Result: Literal \\n found")
|
||||
else:
|
||||
print("Result: Unexpected content")
|
||||
else:
|
||||
print("Note not created")
|
||||
Reference in new issue
Block a user