diff --git a/README.md b/README.md index 517efa0..969a0ae 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ See https://www.dokuwiki.org/wiki:syntax Just use the main python class. It uses `argparse`: -```python src/main.py --dir='some_dokuwiki_root_dir'``` +`python src/main.py --dir='some_dokuwiki_root_dir'` Command line options: @@ -18,6 +18,10 @@ Command line options: - `--frontmatter_tags=true`, whether to generate tags in the converted Hugo markdown. By default, the tool generates tags based on the path to the document. +##### Running unittests + +`python runtests.py` in root folder. `-m unittest` does not work as imports mess up `src`/`test` subfolder structures. + ##### Including it into your python project: Main wiring in `DokuWikiToHugo` - see the tests for an elaborate example. diff --git a/runtests.py b/runtests.py new file mode 100644 index 0000000..41f3dbd --- /dev/null +++ b/runtests.py @@ -0,0 +1,9 @@ +import sys +import unittest + +sys.path.append('src') + +loader = unittest.TestLoader() +testSuite = loader.discover('test') +testRunner = unittest.TextTestRunner(verbosity=2) +testRunner.run(testSuite) diff --git a/src/dokuwiki_to_hugo.py b/src/dokuwiki_to_hugo.py index 853e04f..982b7df 100644 --- a/src/dokuwiki_to_hugo.py +++ b/src/dokuwiki_to_hugo.py @@ -1,13 +1,8 @@ import os import shutil -<<<<<<< HEAD -from hugo_file_config import HugoFileConfig +from hugo_front_matter import HugoFrontMatter from markdown_converter import MarkdownConverter -======= -from src.hugo_front_matter import HugoFrontMatter -from src.markdown_converter import MarkdownConverter ->>>>>>> master class DokuWikiToHugo: diff --git a/test/test_dokuwiki_to_hugo.py b/test/test_dokuwiki_to_hugo.py index a911ee0..8a13c8e 100644 --- a/test/test_dokuwiki_to_hugo.py +++ b/test/test_dokuwiki_to_hugo.py @@ -9,16 +9,17 @@ from src.dokuwiki_to_hugo import DokuWikiToHugo class TestDokuWikiToHugo(TestCase): def tearDown(self): shutil.rmtree('output') + pass def test_doku_to_hugo_converts_home_to_index_markdown_files(self): - DokuWikiToHugo().doku_to_hugo('subdir') - expected = Path("output/subdir/_index.md").read_text() + DokuWikiToHugo().doku_to_hugo('test/subdir') + expected = Path("output/test/subdir/_index.md").read_text() self.assertIn('subdir index', expected) def test_convert_whole_dir(self): - DokuWikiToHugo().doku_to_hugo('subdir') - expected = Path("output/subdir/moar/dokuwiki_header_in_subdir.md").read_text() + DokuWikiToHugo().doku_to_hugo('test/subdir') + expected = Path("output/test/subdir/moar/dokuwiki_header_in_subdir.md").read_text() self.assertIn('+++', expected) # header is there, check self.assertIn('##### some header', expected) # some conversion done, check diff --git a/test/test_hugo_front_matter.py b/test/test_hugo_front_matter.py index 6c4411c..2386b3a 100644 --- a/test/test_hugo_front_matter.py +++ b/test/test_hugo_front_matter.py @@ -10,8 +10,8 @@ class TestHugoFrontMatter(TestCase): def set_file_timestamp(self): date = datetime(2014, 10, 10, 12) u_time = mktime(date.timetuple()) - utime('dokuwiki_header_example.txt', (u_time, u_time)) - utime('subdir/moar/dokuwiki_header_in_subdir.txt', (u_time, u_time)) + utime('test/dokuwiki_header_example.txt', (u_time, u_time)) + utime('test/subdir/moar/dokuwiki_header_in_subdir.txt', (u_time, u_time)) def setUp(self): self.set_file_timestamp() @@ -22,14 +22,16 @@ class TestHugoFrontMatter(TestCase): title = "dokuwiki_header_in_subdir" draft = false tags = [ + "test", "subdir", "moar", "dokuwiki_header_in_subdir" ] + date = "2014-10-10" +++""" - actual_header = self.header.create('subdir/moar/dokuwiki_header_in_subdir.txt') + actual_header = self.header.create('test/subdir/moar/dokuwiki_header_in_subdir.txt') self.assertEqual(expected_header, actual_header) def test_dokuwiki_header_example(self): @@ -37,10 +39,12 @@ date = "2014-10-10" title = "dokuwiki_header_example" draft = false tags = [ + "test", "dokuwiki_header_example" ] + date = "2014-10-10" +++""" - actual_header = self.header.create('dokuwiki_header_example.txt') + actual_header = self.header.create('test/dokuwiki_header_example.txt') self.assertEqual(expected_header, actual_header) diff --git a/test/test_markdown_converter.py b/test/test_markdown_converter.py index a8f5bb0..6e69336 100644 --- a/test/test_markdown_converter.py +++ b/test/test_markdown_converter.py @@ -7,11 +7,11 @@ from src.markdown_converter import MarkdownConverter class TestMarkdownHeader(TestCase): def setUp(self): - self.converter = MarkdownConverter("dokuwiki_example.txt") + self.converter = MarkdownConverter("test/dokuwiki_example.txt") def test_acceptance_test_case(self): # python 3.5 and up - expected = Path("expected_markdown_output.txt").read_text() + expected = Path("test/expected_markdown_output.txt").read_text() actual = self.converter.convert() print(actual)