@@ -25,46 +25,57 @@ def tearDown(self):
2525 shutil .rmtree (self .test_dir )
2626
2727 def test_create_dir_structure (self ):
28- paths = ["test_docs/a" , "test_docs/b" ]
29- create_dir_structure (paths )
30- for path in paths :
31- self .assertTrue (os .path .isdir (path ))
28+ md_text = "A\n B"
29+ base_dir = self .test_dir
30+ create_dir_structure (md_text , base_dir )
31+ self .assertTrue (os .path .isdir (os .path .join (base_dir , "A" )))
32+ self .assertTrue (os .path .isdir (os .path .join (base_dir , "B" )))
3233
3334 def test_create_dir_structure_from_headers (self ):
34- headers = ["# A" , "## B" ]
35- create_dir_structure_from_headers (headers , root = self .test_dir )
35+ # Prepare a markdown file
36+ md_path = os .path .join (self .test_dir , "headers.md" )
37+ with open (md_path , "w" ) as f :
38+ f .write ("# A\n ## B\n " )
39+ create_dir_structure_from_headers (md_path , path = self .test_dir )
3640 self .assertTrue (os .path .isdir (os .path .join (self .test_dir , "A" )))
37- self .assertTrue (os .path .isdir (os .path .join (self .test_dir , "A" , " B" )))
41+ self .assertTrue (os .path .isdir (os .path .join (self .test_dir , "B" )))
3842
3943 def test_create_folders_files (self ):
40- structure = {self .test_dir : ["file1.md" , "file2.md" ]}
41- create_folders_files (structure )
42- for fname in structure [self .test_dir ]:
43- self .assertTrue (os .path .isfile (os .path .join (self .test_dir , fname )))
44+ # Prepare a markdown file
45+ md_path = os .path .join (self .test_dir , "files.md" )
46+ with open (md_path , "w" ) as f :
47+ f .write ("# Section\n ```bash\n echo hello\n ```\n " )
48+ create_folders_files (md_path , path = self .test_dir )
49+ self .assertTrue (os .path .isfile (os .path .join (self .test_dir , "Section" , "1.bash" )))
4450
4551 def test_get_code_extension_dict (self ):
46- ext_dict = get_code_extension_dict ()
47- self .assertIsInstance (ext_dict , dict )
48- self .assertIn ("py" , ext_dict )
52+ content = """```python\n print('hello')\n ```"""
53+ ext_list = ["python" ]
54+ ext_head_list = {"python" : "#!/bin/python" }
55+ result = get_code_extension_dict (content , ext_list , ext_head_list )
56+ self .assertIsInstance (result , list )
57+ self .assertEqual (result [0 ]["extension" ], "python" )
4958
5059 def test_get_dictionary_structure_by_separator_list (self ):
51- paths = [ "a/b/c.txt" , "a/b/d.txt" , "a/e.txt" ]
52- structure = get_dictionary_structure_by_separator_list (paths )
53- self .assertIsInstance (structure , dict )
54- self .assertIn ( "a" , structure )
60+ markdown = """```bash \n echo hello \n ``` \n ```bash \n echo world \n ```"""
61+ blocks = get_dictionary_structure_by_separator_list (markdown )
62+ self .assertIsInstance (blocks , list )
63+ self .assertTrue ( any ( "hello" in block for block in blocks ) )
5564
5665 def test_get_dictionary_structure_from_headers_content (self ):
57- headers = ["# A" , "## B" ]
58- contents = ["desc A" , "desc B" ]
59- structure = get_dictionary_structure_from_headers_content (headers , contents )
66+ # Prepare a markdown file
67+ md_path = os .path .join (self .test_dir , "headers_content.md" )
68+ with open (md_path , "w" ) as f :
69+ f .write ("# A\n desc A\n ## B\n desc B\n " )
70+ structure = get_dictionary_structure_from_headers_content (md_path )
6071 self .assertIsInstance (structure , dict )
6172 self .assertIn ("A" , structure )
6273
6374 def test_get_header_list (self ):
6475 markdown_text = "# A\n ## B"
6576 headers = get_header_list (markdown_text )
66- self .assertIn ("# A" , headers )
67- self .assertIn ("## B" , headers )
77+ self .assertIn ("A" , headers )
78+ self .assertIn ("B" , headers )
6879
6980 def test_get_url_list (self ):
7081 markdown_text = "[OpenAI](https://openai.com)"
0 commit comments