From 3d3873b699dfa8240981d56fc902810d76e9470c Mon Sep 17 00:00:00 2001 From: Olivier Date: Mon, 19 Oct 2026 11:51:58 -0400 Subject: [PATCH] chore: v0.3.0; tests: drop dead export_to_csv and shadowed set_default tests, restore create checks --- src/onyx.py | 2 +- tests/test_obsidian_cli.py | 92 +++++++------------------------------- 2 files changed, 16 insertions(+), 78 deletions(-) diff --git a/src/onyx.py b/src/onyx.py index f4aab7c..1866626 100644 --- a/src/onyx.py +++ b/src/onyx.py @@ -974,7 +974,7 @@ def _periodic_output_options(command): help="Don't open Obsidian; a newly created note keeps raw Templater syntax " "until Obsidian processes it")(command) -@click.version_option(version='0.2.0', prog_name='onyx') +@click.version_option(version='0.3.0', prog_name='onyx') @click.group(name='onyx') def cli(): """Onyx - Interact with Obsidian vaults from the command line diff --git a/tests/test_obsidian_cli.py b/tests/test_obsidian_cli.py index 39f0d21..cd2bd17 100644 --- a/tests/test_obsidian_cli.py +++ b/tests/test_obsidian_cli.py @@ -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"""