chore: v0.3.0; tests: drop dead export_to_csv and shadowed set_default tests, restore create checks
This commit is contained in:
1 parent
0f763f98ed
commit
3d3873b699
2 files changed
+16
-78
No files matched your search
+15
-77
@@ -35,89 +35,12 @@ class TestOnyxCLI(unittest.TestCase):
|
||||
shutil.rmtree(self.test_dir, ignore_errors=True)
|
||||
shutil.rmtree(self.temp_config_dir, ignore_errors=True)
|
||||
|
||||
def test_set_default_vault(self):
|
||||
"""Test setting default vault"""
|
||||
self.cli.set_default_vault('new_vault', str(self.test_dir))
|
||||
self.assertEqual(self.cli.default_vault, 'new_vault')
|
||||
|
||||
config = yaml.safe_load(self.cli.config_file.read_text(encoding='utf-8-sig'))
|
||||
self.assertEqual(config['default_vault'], 'new_vault')
|
||||
self.assertEqual(Path(config['vaults']['new_vault']), self.test_dir.resolve())
|
||||
|
||||
def test_create_note(self):
|
||||
"""Test note creation"""
|
||||
# Test basic note creation
|
||||
self.cli.create_note('test.md', 'Test content')
|
||||
note_path = self.test_dir / 'test.md'
|
||||
self.assertTrue(note_path.exists())
|
||||
|
||||
def test_writes_keep_lf_without_bom(self):
|
||||
"""Append and frontmatter edits write LF, no BOM, even on Windows"""
|
||||
note_path = self.test_dir / 'lf.md'
|
||||
note_path.write_bytes(b'---\nstatus: draft\n---\n# Journal\n')
|
||||
|
||||
self.cli.create_note('lf.md', '### 10:00 - Entry\nline', append=True)
|
||||
self.cli.frontmatter_edit('lf', ('status',), ('done',))
|
||||
|
||||
data = note_path.read_bytes()
|
||||
self.assertNotIn(b'\r', data)
|
||||
self.assertFalse(data.startswith(b'\xef\xbb\xbf'))
|
||||
self.assertIn(b'status: done', data)
|
||||
self.assertTrue(data.endswith(b'# Journal\n\n### 10:00 - Entry\nline'))
|
||||
|
||||
@unittest.skip("Method export_to_csv not implemented")
|
||||
def test_export_to_csv(self):
|
||||
"""Test exporting note frontmatter to CSV"""
|
||||
# Create a test note with frontmatter
|
||||
note_content = """---
|
||||
title: Test Note
|
||||
tags: [tag1, tag2]
|
||||
status: in-progress
|
||||
date: 2025-10-28
|
||||
custom: value
|
||||
---
|
||||
Note content"""
|
||||
self.cli.create_note('test_note.md', note_content)
|
||||
|
||||
# Test export with specific columns included
|
||||
output_file = self.test_dir / 'output1.csv'
|
||||
self.cli.export_to_csv('test_note', str(output_file), include_columns=['title', 'status', 'date'])
|
||||
with open(output_file, 'r', encoding='utf-8') as f:
|
||||
content = f.read().strip()
|
||||
self.assertEqual(content, 'title,status,date\nTest Note,in-progress,2025-10-28')
|
||||
|
||||
# Test export excluding specific columns
|
||||
output_file = self.test_dir / 'output2.csv'
|
||||
self.cli.export_to_csv('test_note', str(output_file), exclude_columns=['tags', 'custom'])
|
||||
with open(output_file, 'r', encoding='utf-8') as f:
|
||||
content = f.read().strip()
|
||||
self.assertEqual(content, 'title,status,date\nTest Note,in-progress,2025-10-28')
|
||||
|
||||
# Test export with both include and exclude (exclude takes precedence)
|
||||
output_file = self.test_dir / 'output3.csv'
|
||||
self.cli.export_to_csv('test_note', str(output_file),
|
||||
include_columns=['title', 'status', 'date', 'custom'],
|
||||
exclude_columns=['status'])
|
||||
with open(output_file, 'r', encoding='utf-8') as f:
|
||||
content = f.read().strip()
|
||||
self.assertEqual(content, 'title,date,custom\nTest Note,2025-10-28,value')
|
||||
|
||||
# Test with non-existent note
|
||||
with self.assertRaises(click.UsageError) as context:
|
||||
self.cli.export_to_csv('non_existent', 'output.csv')
|
||||
self.assertTrue("not found in vault" in str(context.exception))
|
||||
|
||||
# Test with note without frontmatter
|
||||
self.cli.create_note('no_frontmatter.md', 'Just content')
|
||||
with self.assertRaises(click.UsageError) as context:
|
||||
self.cli.export_to_csv('no_frontmatter', 'output.csv')
|
||||
self.assertTrue("No frontmatter found" in str(context.exception))
|
||||
|
||||
# Test with empty frontmatter
|
||||
self.cli.create_note('empty_frontmatter.md', '---\n---\nContent')
|
||||
with self.assertRaises(click.UsageError) as context:
|
||||
self.cli.export_to_csv('empty_frontmatter', 'output.csv')
|
||||
self.assertTrue("Empty frontmatter" in str(context.exception))
|
||||
self.assertEqual(note_path.read_text(encoding='utf-8-sig'), 'Test content')
|
||||
|
||||
# Test note creation with auto-extension
|
||||
@@ -136,6 +59,21 @@ Note content"""
|
||||
(self.test_dir / 'test.md').read_text(encoding='utf-8-sig'),
|
||||
'New content\nAdditional content'
|
||||
)
|
||||
|
||||
def test_writes_keep_lf_without_bom(self):
|
||||
"""Append and frontmatter edits write LF, no BOM, even on Windows"""
|
||||
note_path = self.test_dir / 'lf.md'
|
||||
note_path.write_bytes(b'---\nstatus: draft\n---\n# Journal\n')
|
||||
|
||||
self.cli.create_note('lf.md', '### 10:00 - Entry\nline', append=True)
|
||||
self.cli.frontmatter_edit('lf', ('status',), ('done',))
|
||||
|
||||
data = note_path.read_bytes()
|
||||
self.assertNotIn(b'\r', data)
|
||||
self.assertFalse(data.startswith(b'\xef\xbb\xbf'))
|
||||
self.assertIn(b'status: done', data)
|
||||
self.assertTrue(data.endswith(b'# Journal\n\n### 10:00 - Entry\nline'))
|
||||
|
||||
|
||||
def test_frontmatter_operations(self):
|
||||
"""Test frontmatter operations"""
|
||||
|
||||
Reference in new issue
Block a user