Skip to content

Commit

Permalink
add frontmatter test
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Sep 28, 2024
1 parent dfd6acb commit efdbaaa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
2 changes: 1 addition & 1 deletion test/data
Submodule data updated 22 files
+ reference_data/frontmatter/all/My Notebook/958054fb824e46249c99bab54040bef0.png
+29 −0 reference_data/frontmatter/all/My Notebook/Another note.md
+19 −0 reference_data/frontmatter/all/My Notebook/Nested Notebook/note in other notebook with same name.md
+32 −0 reference_data/frontmatter/all/My Notebook/Sample note with completed reminder.md
+ reference_data/frontmatter/all/My Notebook/f02b62f4a51a47138c053ecdbe68ecf6.png
+13 −0 reference_data/frontmatter/all/My Notebook/photo card (image only).md
+14 −0 reference_data/frontmatter/all/Second notebook/note in second notebook with open reminder.md
+ reference_data/frontmatter/joplin/My Notebook/958054fb824e46249c99bab54040bef0.png
+27 −0 reference_data/frontmatter/joplin/My Notebook/Another note.md
+18 −0 reference_data/frontmatter/joplin/My Notebook/Nested Notebook/note in other notebook with same name.md
+31 −0 reference_data/frontmatter/joplin/My Notebook/Sample note with completed reminder.md
+ reference_data/frontmatter/joplin/My Notebook/f02b62f4a51a47138c053ecdbe68ecf6.png
+11 −0 reference_data/frontmatter/joplin/My Notebook/photo card (image only).md
+12 −0 reference_data/frontmatter/joplin/Second notebook/note in second notebook with open reminder.md
+ reference_data/frontmatter/obsidian/My Notebook/958054fb824e46249c99bab54040bef0.png
+17 −0 reference_data/frontmatter/obsidian/My Notebook/Another note.md
+11 −0 reference_data/frontmatter/obsidian/My Notebook/Nested Notebook/note in other notebook with same name.md
+24 −0 reference_data/frontmatter/obsidian/My Notebook/Sample note with completed reminder.md
+ reference_data/frontmatter/obsidian/My Notebook/f02b62f4a51a47138c053ecdbe68ecf6.png
+1 −0 reference_data/frontmatter/obsidian/My Notebook/photo card (image only).md
+2 −0 reference_data/frontmatter/obsidian/Second notebook/note in second notebook with open reminder.md
+0 −48 test_data/default_format/testcases.json
83 changes: 46 additions & 37 deletions test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ def setUp(self):
# use the same seed before every test to get reproducible uuids
random.seed(42)

# mock a argparse namespace
# https://stackoverflow.com/a/51197422/7410886
self.config = SimpleNamespace(
format=None,
frontmatter=None,
global_resource_folder=None,
print_tree=False,
exclude_notes=None,
exclude_notes_with_tags=None,
exclude_tags=None,
include_notes=None,
include_notes_with_tags=None,
include_tags=None,
no_progress_bars=True,
)

def assert_dir_trees_equal(self, dir1: Path, dir2: Path):
"""Check that two directories are equal, including file contents."""
self.assertTrue(dir1.exists(), dir1)
Expand Down Expand Up @@ -112,22 +128,10 @@ def test_formats(self, test_input):
shutil.rmtree(test_data_output, ignore_errors=True)
reference_data = Path("test/data/reference_data") / test_input[0].parent

config = SimpleNamespace(
input=test_data,
format=test_input[0].parts[0],
output_folder=test_data_output,
frontmatter=None,
global_resource_folder=None,
print_tree=False,
exclude_notes=None,
exclude_notes_with_tags=None,
exclude_tags=None,
include_notes=None,
include_notes_with_tags=None,
include_tags=None,
no_progress_bars=True,
)
jimmy.jimmy(config)
self.config.input = test_data
self.config.format = test_input[0].parts[0]
self.config.output_folder = test_data_output
jimmy.jimmy(self.config)

# Skip only here to catch potential errors during conversion.
if not reference_data.exists():
Expand All @@ -137,11 +141,11 @@ def test_formats(self, test_input):

@parameterized.expand(
[
("single_folder", ["default_format/arbitrary_folder"]),
("multiple_folders", ["default_format/arbitrary_folder"] * 2),
("single_file", ["default_format/arbitrary_folder/plaintext.txt"]),
("multiple_files", ["default_format/arbitrary_folder/plaintext.txt"] * 2),
("markdown_file", ["default_format/arbitrary_folder/sample.md"]),
["single_folder", ["default_format/arbitrary_folder"]],
["multiple_folders", ["default_format/arbitrary_folder"] * 2],
["single_file", ["default_format/arbitrary_folder/plaintext.txt"]],
["multiple_files", ["default_format/arbitrary_folder/plaintext.txt"] * 2],
["markdown_file", ["default_format/arbitrary_folder/sample.md"]],
]
)
def test_default_format(self, test_name, test_input):
Expand All @@ -155,22 +159,9 @@ def test_default_format(self, test_name, test_input):
# separate folder for each input
reference_data = Path("test/data/reference_data/default_format") / test_name

config = SimpleNamespace(
input=test_data,
format=None,
output_folder=test_data_output,
frontmatter=None,
global_resource_folder=None,
print_tree=False,
exclude_notes=None,
exclude_notes_with_tags=None,
exclude_tags=None,
include_notes=None,
include_notes_with_tags=None,
include_tags=None,
no_progress_bars=True,
)
jimmy.jimmy(config)
self.config.input = test_data
self.config.output_folder = test_data_output
jimmy.jimmy(self.config)

if len(test_input) == 1:
self.assert_dir_trees_equal(test_data_output, reference_data)
Expand All @@ -181,3 +172,21 @@ def test_default_format(self, test_name, test_input):
)
reference = reference_data.parent / (reference_data.name + f" {index}")
self.assert_dir_trees_equal(actual_data, reference)

@parameterized.expand(["all", "joplin", "obsidian"])
def test_frontmatter(self, frontmatter):
"""Test the frontmatter generation."""

test_data = [Path("test/data/test_data/joplin/test_1/29_04_2024.jex")]
test_data_output = Path("tmp_output/frontmatter") / frontmatter
shutil.rmtree(test_data_output, ignore_errors=True)
# separate folder for each input
reference_data = Path("test/data/reference_data/frontmatter") / frontmatter

self.config.input = test_data
self.config.format = "joplin"
self.config.output_folder = test_data_output
self.config.frontmatter = frontmatter
jimmy.jimmy(self.config)

self.assert_dir_trees_equal(test_data_output, reference_data)

0 comments on commit efdbaaa

Please sign in to comment.