Ejemplo n.º 1
0
 def test_raise_to_meta(self):
     path = Path.cwd().joinpath("mocks/post_1.md")
     mtpr = MetaPostReader()
     # Key not exist in source file
     mtpr.add_meta_cfg("missing_key", "str", True)
     mtpr.read_file(path)
     with self.assertRaises(MetaPostReaderError):
         mtpr.to_meta()
Ejemplo n.º 2
0
 def test_ok_export_to_meta_dict_json(self):
     path = Path.cwd().joinpath("mocks/post_1.md")
     mtpr = MetaPostReader()
     mtpr.add_meta_cfg("title", "str", True)
     mtpr.read_file(path)
     # to meta
     exp1 = [{
         "title": "A mock post",
         '_content_markdown_': 'some content',
         "_filepath_": str(path),
         "_filename_": "post_1",
         "_last_update_": mtpr.mtp_list[0]._get_last_update_dt(path)
     }]
     act1 = mtpr.to_meta()
     self.assertEqual(exp1, act1)
     # to html
     exp2 = ["<p>some content</p>"]
     act2 = mtpr.to_html()
     self.assertEqual(exp2, act2)
     # to dict
     exp3 = [{"meta": exp1[0], "html": exp2[0]}]
     act3 = mtpr.to_dict()
     self.assertEqual(exp3, act3)
     # to json
     exp4 = json.loads(mtpr.to_json())
     act4 = mtpr.to_dict()
     self.assertEqual(exp4, act4)