1
- #!/usr/bin/env python3
2
-
3
- import argparse
4
- import sys
5
- import unittest
6
-
7
- from dactyl import dactyl_build
8
-
9
- class MockCliArgs :
10
- version = None
11
- bypass_errors = False
12
- config = "test-config.yml"
13
- debug = False
14
- quiet = False
15
- out_dir = None
16
- skip_preprocessor = False
17
-
18
- from dactyl .config import DactylConfig
19
-
20
- class MockDactylConfig (DactylConfig ):
21
- def load_filters (self ):
22
- pass
23
-
24
- try :
25
- dc = MockDactylConfig (MockCliArgs )
26
- dactyl_build .config = dc
27
- except ModuleNotFoundError :
28
- print ("Oh no! A module wasn't found, and this statement is extremely unhelpful!" )
29
-
30
- from jinja2 import Template
31
- mocktemplate = Template ("This page is {{ currentpage.name }}." )
32
-
33
- class TestDactylBuild (unittest .TestCase ):
34
- #IMPORTANT: Please run these tests from the "tests" directory, to ensure test config files and mocks are correctly loaded.
35
-
36
- #P1 tests listed below
37
-
38
- def test_default_pdf_name (self ):
39
- test_result = dactyl_build .default_pdf_name ("conditionals" )
40
- assert test_result == "Conditional_Text_Target.pdf"
41
-
42
- def test_get_target (self ):
43
- assert dactyl_build .get_target (None ) == {"name" : "test_target" }
44
- assert dactyl_build .get_target ("conditionals" ) == {"name" : "conditionals" , "display_name" : "Conditional Text Target" }
45
- assert dactyl_build .get_target ({"name" : "runtime_target" }) == {"name" : "runtime_target" }
46
-
47
- def test_get_pages (self ):
48
- assert dactyl_build .get_pages (dactyl_build .get_target ("test_target" ), False ) == [{'name' : 'filters_page' , 'category' : 'Filters' , 'filters' : ['mock_filter' ], 'targets' : ['test_target' ], 'html' : 'filters_page.html' }, {'name' : 'test_page' , 'category' : 'Tests' , 'html' : 'test.html' , 'targets' : ['test_target' ]}]
49
-
50
- def test_get_filters_for_page (self ):
51
- # Please note: due to the mock setup for unit testing, this function will always return an empty set. Refactoring is recommended to verify the remaining functionality for this method.
52
- assert dactyl_build .get_filters_for_page (dactyl_build .config ["pages" ][0 ], dactyl_build .get_target ("filters_target" )) == set ()
53
-
54
- def test_parse_markdown (self ):
55
- output = dactyl_build .parse_markdown (dactyl_build .config ["pages" ][2 ], "filters_target" , dactyl_build .config ["pages" ], [], "html" , "" , False )
56
-
57
- def test_render_page (self ):
58
- output = dactyl_build .render_page (dactyl_build .config ["pages" ][2 ], "filters_target" , dactyl_build .config ["pages" ], "html" , "" , [], mocktemplate , False )
59
- assert output == "This page is md_test."
60
-
61
- #P2 tests listed below
62
-
63
- def test_target_slug_name (self ):
64
- assert dactyl_build .target_slug_name ("conditionals" ) == "Conditional_Text_Target"
65
-
66
- def test_make_adhoc_target (self ):
67
- assert dactyl_build .make_adhoc_target (["gfm-compat.md" ]) == {'name' : '__ADHOC__' , 'display_name' : 'GitHub Markdown Compatibility' }
68
-
69
- def test_get_categories (self ):
70
- assert dactyl_build .get_categories (dactyl_build .config ["pages" ]) == ['Filters' , 'Tests' , 'Markdown' ]
71
-
72
- if __name__ == '__main__' :
73
- unittest .main ()
1
+ #!/usr/bin/env python3
2
+
3
+ import argparse
4
+ import sys
5
+ import unittest
6
+
7
+ from dactyl import dactyl_build
8
+
9
+ class MockCliArgs :
10
+ version = None
11
+ bypass_errors = False
12
+ config = "test-config.yml"
13
+ debug = False
14
+ quiet = False
15
+ out_dir = None
16
+ skip_preprocessor = False
17
+
18
+ from dactyl .config import DactylConfig
19
+
20
+ class MockDactylConfig (DactylConfig ):
21
+ def load_filters (self ):
22
+ pass
23
+
24
+ try :
25
+ dc = MockDactylConfig (MockCliArgs )
26
+ dactyl_build .config = dc
27
+ except ModuleNotFoundError :
28
+ print ("Oh no! A module wasn't found, and this statement is extremely unhelpful!" )
29
+
30
+ from jinja2 import Template
31
+ mocktemplate = Template ("This page is {{ currentpage.name }}." )
32
+
33
+ class TestDactylBuild (unittest .TestCase ):
34
+ #IMPORTANT: Please run these tests from the "tests" directory, to ensure test config files and mocks are correctly loaded.
35
+
36
+ def test_default_pdf_name (self ):
37
+ test_result = dactyl_build .default_pdf_name ("conditionals" )
38
+ assert test_result == "Conditional_Text_Target.pdf"
39
+
40
+ def test_get_target (self ):
41
+ assert dactyl_build .get_target (None ) == {"name" : "test_target" }
42
+ assert dactyl_build .get_target ("conditionals" ) == {"name" : "conditionals" , "display_name" : "Conditional Text Target" }
43
+ assert dactyl_build .get_target ({"name" : "runtime_target" }) == {"name" : "runtime_target" }
44
+
45
+ def test_get_pages (self ):
46
+ assert dactyl_build .get_pages (dactyl_build .get_target ("test_target" ), False ) == [{'name' : 'filters_page' , 'category' : 'Filters' , 'filters' : ['mock_filter' ], 'targets' : ['test_target' ], 'html' : 'filters_page.html' }, {'name' : 'test_page' , 'category' : 'Tests' , 'html' : 'test.html' , 'targets' : ['test_target' ]}]
47
+
48
+ def test_get_filters_for_page (self ):
49
+ # Please note: due to the mock setup for unit testing, this function will always return an empty set. Refactoring is recommended to verify the remaining functionality for this method.
50
+ assert dactyl_build .get_filters_for_page (dactyl_build .config ["pages" ][0 ], dactyl_build .get_target ("filters_target" )) == set ()
51
+
52
+ def test_parse_markdown (self ):
53
+ output = dactyl_build .parse_markdown (dactyl_build .config ["pages" ][2 ], "filters_target" , dactyl_build .config ["pages" ], [], "html" , "" , False )
54
+
55
+ def test_render_page (self ):
56
+ output = dactyl_build .render_page (dactyl_build .config ["pages" ][2 ], "filters_target" , dactyl_build .config ["pages" ], "html" , "" , [], mocktemplate , False )
57
+ assert output == "This page is md_test."
58
+
59
+ def test_target_slug_name (self ):
60
+ print ("target_slug_name is" , dactyl_build .target_slug_name ("conditionals" ))
61
+ fields_to_use = ["display_name" ]
62
+ sep = ","
63
+ assert dactyl_build .target_slug_name ("conditionals" , fields_to_use , sep ) == "Conditional_Text_Target"
64
+
65
+ def test_es_index_name (self ):
66
+ test_target = dactyl_build .get_target ("es_index_test_target" )
67
+ dactyl_build .config ["es_index_fields" ] = ["foo1" , "foo2" ]
68
+ dactyl_build .config ["es_index_separator" ] = "--"
69
+ assert dactyl_build .es_index_name (test_target ) == "Foo_Value_1--Foo_Value_TWOOOO"
70
+
71
+ def test_make_adhoc_target (self ):
72
+ assert dactyl_build .make_adhoc_target (["gfm-compat.md" ]) == {'name' : '__ADHOC__' , 'display_name' : 'GitHub Markdown Compatibility' }
73
+
74
+ def test_get_categories (self ):
75
+ assert dactyl_build .get_categories (dactyl_build .config ["pages" ]) == ['Filters' , 'Tests' , 'Markdown' ]
76
+
77
+ if __name__ == '__main__' :
78
+ unittest .main ()
0 commit comments