OpenCores
URL https://opencores.org/ocsvn/radiohdl/radiohdl/trunk

Subversion Repositories radiohdl

[/] [radiohdl/] [trunk/] [base/] [test/] [t_hdl_configfile.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
import unittest
2
from configfile import *
3
from hdl_configfile import *
4
 
5
class Test_construction(unittest.TestCase):
6
    "Class to the various ways of construction"
7
 
8
    def test_wrong_filename(self):
9
        "Test constructor with non-existing file"
10
        self.assertRaises(ConfigFileException, ConfigFile, "/Is/Not/A/Valid/Directory")
11
 
12
    def test_empty_dictfile(self):
13
        "Test constructor with empty config file"
14
        cfg = ConfigFile("./cdf_dir/empty_file/empty_dict.txt")
15
        self.assertEqual(len(cfg.content), 0)
16
 
17
    def test_comment_only_dictfile(self):
18
        "Test constructor with comment-only config files"
19
        cfg = ConfigFile("./cdf_dir/empty_file/comment_only_dict.txt")
20
        self.assertEqual(len(cfg.content), 0)
21
 
22
 
23
class Test_key_value_spacing(unittest.TestCase):
24
    "Class to the various kind of spacing between the keys and the values"
25
 
26
    def test_key_value_spacing(self):
27
        cfg = ConfigFile("./cdf_dir/correct_files/key_value_test.txt")
28
        self.assertEqual(cfg.space_key_1, "value_1")
29
        self.assertEqual(cfg.space_key_2, "value_2")
30
        self.assertEqual(cfg.space_key_3, "value_3")
31
        self.assertEqual(cfg.space_key_4, "value_4")
32
        self.assertEqual(cfg.space_key_5, "value_5")
33
        self.assertEqual(cfg.space_key_6, "value_6")
34
        self.assertEqual(cfg.space_key_7, "value_7")
35
        self.assertEqual(cfg.multi_key_1, "value10 value11 value12")
36
        self.assertEqual(cfg.multi_key_2, "value20, value21, value22")
37
        self.assertEqual(cfg.multi_key_3, "value30 value31 value32 value33")
38
        self.assertEqual(cfg.multi_key_4, "value40 = value41 = value42")
39
        self.assertEqual(cfg.tricky_key_1, "")
40
        self.assertEqual(cfg.tricky_key_2, "tricky_value_2")
41
        self.assertEqual(cfg.tricky_key_3, "")
42
        self.assertEqual(cfg.section_headers, ['"my_section"'])
43
        self.assertEqual(cfg.warning_key_1,
44
            "Be aware that multiline values can be tricky:  this also belongs to previous key 'warning_key_1'")
45
        # also test attribute access versus item access
46
        self.assertEqual(cfg.multi_key_2, cfg['multi_key_2'])
47
        print cfg.content
48
 
49
    def test_sections(self):
50
        cfg = ConfigFile("./cdf_dir/correct_files/section_test.txt")
51
        self.assertEqual(cfg.global_key_1, "global_1"),
52
        self.assertEqual(cfg.global_key_2, '[ "aap", "noot", "mies" ]'),
53
        self.assertEqual(cfg.just_some_key_1, "section2 value1"),
54
        self.assertEqual(cfg.just_some_key_2, "section2 value2"),
55
        self.assertEqual(cfg.section_headers, ['section_1', 'section_2'])
56
 
57
    def test_dangling_value(self):
58
        "Test if a value without a key is detected"
59
        self.assertRaises(ConfigFileException, ConfigFile, "./cdf_dir/wrong_files/dangling_test.txt")
60
 
61
    def test_keys_with_spaces(self):
62
        "Test if a key that contains spaces is detected"
63
        self.assertRaises(ConfigFileException, ConfigFile, "./cdf_dir/wrong_files/wrong_key_test.txt")
64
 
65
 
66
class Test_reference_key_substitution(unittest.TestCase):
67
    "Class to the the substitution of referenced keys."
68
 
69
    def test_read_the_file(self):
70
        cfg = ConfigFile("./cdf_dir/referenced_files/reference_test.txt")
71
        self.assertEqual(cfg.early_ref_key1, "before <ref_key_2> is defined")
72
        self.assertEqual(cfg.simple_ref_1, "a value with <ref_key_1>")
73
        self.assertEqual(cfg.double_ref_1, "a value with twice <ref_key_1><ref_key_1>")
74
        self.assertEqual(cfg.triple_key_1, "its here <ref_key_1> and here <ref_key_1> and here <ref_key_1>!!!")
75
        self.assertEqual(cfg.triple_key_2, "its here <ref_key_2> and here <ref_key_1>!!!")
76
        self.assertEqual(cfg.ref_only_key_1, "<ref_key_1>")
77
        self.assertEqual(cfg.wrong_ref_1, "what will double brackets <<ref_key_2>> do?")
78
        self.assertEqual(cfg.undefined_key_1, "reference to <non existing key>")
79
 
80
        self.assertEqual(cfg.nested_key_1, "some_value")
81
        self.assertEqual(cfg.nested_key_2, "<nested_key_1>")
82
        self.assertEqual(cfg.nested_key_3, "<nested_key_2>")
83
        self.assertEqual(cfg.reverse_nested_key_1, "<reverse_nested_key_2>")
84
        self.assertEqual(cfg.reverse_nested_key_2, "<reverse_nested_key_3>")
85
        self.assertEqual(cfg.reverse_nested_key_3, "some_value")
86
        self.assertEqual(cfg.mutual_key_1, "<mutual_key_2>")
87
        self.assertEqual(cfg.mutual_key_2, "<mutual_key_1>")
88
        self.assertEqual(cfg.loop_key_1, "<loop_key_1>")
89
 
90
        cfg.resolve_key_references()
91
 
92
        self.assertEqual(cfg.early_ref_key1, "before multiple words in the value is defined")
93
        self.assertEqual(cfg.simple_ref_1, "a value with single_reference")
94
        self.assertEqual(cfg.double_ref_1, "a value with twice single_referencesingle_reference")
95
        self.assertEqual(cfg.triple_key_1, "its here single_reference and here single_reference and here single_reference!!!")
96
        self.assertEqual(cfg.triple_key_2, "its here multiple words in the value and here single_reference!!!")
97
        self.assertEqual(cfg.ref_only_key_1, "single_reference")
98
        self.assertEqual(cfg.wrong_ref_1, "what will double brackets <<ref_key_2>> do?")
99
        self.assertEqual(cfg.undefined_key_1, "reference to <non existing key>")
100
 
101
        self.assertEqual(cfg.nested_key_1, "some_value")
102
        self.assertEqual(cfg.nested_key_2, "some_value")
103
        self.assertEqual(cfg.nested_key_3, "some_value")
104
        self.assertEqual(cfg.reverse_nested_key_1, "<reverse_nested_key_3>")
105
        self.assertEqual(cfg.reverse_nested_key_2, "some_value")
106
        self.assertEqual(cfg.reverse_nested_key_3, "some_value")
107
        self.assertEqual(cfg.mutual_key_1, "<mutual_key_1>")
108
        self.assertEqual(cfg.mutual_key_2, "<mutual_key_1>")
109
        self.assertEqual(cfg.loop_key_1, "<loop_key_1>")
110
 
111
 
112
class Test_hdltool_file(unittest.TestCase):
113
    "Class to test the hdltool class."
114
 
115
    def test_read_good_hdltool_file(self):
116
        tool = HdlTool("./cdf_dir/hdltool_files/hdl_tool_quartus.cfg")
117
        self.assertEqual(tool.user_environment_variables, "altera_hw_tcl_keep_temp_files        1")
118
 
119
 
120
class Test_hdl_buildset_file(unittest.TestCase):
121
    "Class to test the hdltool class."
122
 
123
    def test_read_good_hdlbuildset_file(self):
124
        buildset = HdlBuildset("./cdf_dir/hdlbuildset_files/hdl_buildset_unb1.cfg")
125
        self.assertEqual(buildset.buildset_name, "unb1")
126
        self.assertEqual(buildset.technology_names, "ip_stratixiv")
127
        self.assertEqual(buildset.lib_root_dirs, "$RADIOHDL/libraries $RADIOHDL/applications $RADIOHDL/boards")
128
 
129
    def test_read_wrong_hdlbuildset_file(self):
130
        self.assertRaises(ConfigFileException, HdlBuildset, "./cdf_dir/hdlbuildset_files/hdl_buildset_wrong.cfg")
131
 
132
 
133
class Test_hdllib_file(unittest.TestCase):
134
    "Class to test the hdllib class."
135
 
136
    def test_read_good_hdllib_file(self):
137
        lib = HdlLib("./cdf_dir/hdllib_files/test_hdllib.cfg")
138
        self.assertEqual(lib.hdl_lib_name, "technology")
139
        self.assertEqual(lib.hdl_library_clause_name, "technology_lib")
140
        self.assertEqual(lib.hdl_lib_technology, "")
141
 
142
    def test_read_wrong_hdllib_file(self):
143
        self.assertRaises(ConfigFileException, HdlLib, "./cdf_dir/hdllib_files/hdllib_wrong.cfg")
144
 
145
if __name__ == '__main__':
146
    unittest.main(verbosity=2)
147
 

powered by: WebSVN 2.1.0

© copyright 1999-2019 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.