feat: Implement the Onyx Obsidian CLI tool, including its source, tests, and executable build artifacts.
This commit is contained in:
1 parent
af43694c98
commit
21837be512
16 files changed
+217
-146
No files matched your search
+42
-52
@@ -1,58 +1,48 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
# Setup test vault
|
||||
vault_path = Path("test_vault_exe").resolve()
|
||||
if vault_path.exists():
|
||||
shutil.rmtree(vault_path)
|
||||
vault_path.mkdir(exist_ok=True)
|
||||
|
||||
# Path to executable
|
||||
exe_path = Path("dist/onyx.exe").resolve()
|
||||
|
||||
print(f"Testing executable at: {exe_path}")
|
||||
|
||||
# Create config for the test
|
||||
# We need to set the config file location for the exe.
|
||||
# The exe looks at Path.home() / '.onyx-cli' / 'config.yaml'
|
||||
# We can't easily change Path.home() for a subprocess without changing env vars that python respects?
|
||||
# On Windows, Path.home() usually uses USERPROFILE.
|
||||
# Let's try setting USERPROFILE to a temp dir.
|
||||
|
||||
env = os.environ.copy()
|
||||
temp_home = Path("temp_home").resolve()
|
||||
temp_home.mkdir(exist_ok=True)
|
||||
env["USERPROFILE"] = str(temp_home)
|
||||
|
||||
# Create config in temp home
|
||||
config_dir = temp_home / ".onyx-cli"
|
||||
config_dir.mkdir(parents=True, exist_ok=True)
|
||||
(config_dir / "config.yaml").write_text(f"default_vault: test\nvaults:\n test: {str(vault_path).replace(os.sep, '/')}", encoding="utf-8")
|
||||
|
||||
# Run the command
|
||||
cmd = [str(exe_path), "create", "exe_newline_test", "--content", "Line1\\nLine2", "--vault", "test"]
|
||||
print(f"Running: {cmd}")
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, env=env, capture_output=True, text=True)
|
||||
print("STDOUT:", result.stdout)
|
||||
print("STDERR:", result.stderr)
|
||||
def test_exe():
|
||||
exe_path = Path('dist/onyx.exe').resolve()
|
||||
if not exe_path.exists():
|
||||
print(f"Executable not found at {exe_path}")
|
||||
sys.exit(1)
|
||||
|
||||
test_dir = Path('test_vault_exe')
|
||||
if test_dir.exists():
|
||||
shutil.rmtree(test_dir)
|
||||
test_dir.mkdir()
|
||||
|
||||
if result.returncode != 0:
|
||||
print("Command failed")
|
||||
print(f"Testing executable: {exe_path}")
|
||||
|
||||
# Set default vault
|
||||
cmd = [str(exe_path), 'set-default', 'test_vault_exe', '--path', str(test_dir.resolve())]
|
||||
print(f"Running: {' '.join(cmd)}")
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
# Create note without extension
|
||||
cmd = [str(exe_path), 'create', 'exe_note1', '--content', 'content']
|
||||
print(f"Running: {' '.join(cmd)}")
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
if (test_dir / 'exe_note1.md').exists():
|
||||
print("PASS: exe_note1.md created")
|
||||
else:
|
||||
note_path = vault_path / "exe_newline_test.md"
|
||||
if note_path.exists():
|
||||
content = note_path.read_text(encoding='utf-8-sig')
|
||||
print(f"Content repr: {repr(content)}")
|
||||
if '\n' in content and '\\n' not in content:
|
||||
print("SUCCESS: Real newline found")
|
||||
else:
|
||||
print("FAILURE: Unexpected content")
|
||||
else:
|
||||
print("Note not created")
|
||||
print("FAIL: exe_note1.md NOT created")
|
||||
|
||||
# Create note with .txt extension
|
||||
cmd = [str(exe_path), 'create', 'exe_note2.txt', '--content', 'content']
|
||||
print(f"Running: {' '.join(cmd)}")
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
if (test_dir / 'exe_note2.txt.md').exists():
|
||||
print("PASS: exe_note2.txt.md created")
|
||||
else:
|
||||
print("FAIL: exe_note2.txt.md NOT created")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error running exe: {e}")
|
||||
# Cleanup
|
||||
shutil.rmtree(test_dir)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_exe()
|
||||
Reference in new issue
Block a user