|
1 | 1 | import os |
2 | 2 | import unittest |
3 | | -from mybatis_mapper2sql import create_mapper, get_child_statement |
| 3 | +import mybatis_mapper2sql |
| 4 | + |
| 5 | +base_dir = os.path.abspath(os.path.dirname(__file__)) |
| 6 | +xml = os.path.join(base_dir, 'test.xml') |
4 | 7 |
|
5 | 8 |
|
6 | 9 | class Mapper2SqlTest(unittest.TestCase): |
7 | 10 |
|
8 | 11 | @classmethod |
9 | 12 | def setUpClass(cls): |
10 | | - base_dir = os.path.abspath(os.path.dirname(__file__)) |
11 | | - xml = os.path.join(base_dir, 'test.xml') |
12 | | - cls.mapper, cls.xml_raw_text = create_mapper(xml=xml) |
| 13 | + cls.mapper, cls.xml_raw_text = mybatis_mapper2sql.create_mapper(xml=xml) |
13 | 14 | print("============XML_RAW_TEXT============") |
14 | 15 | print(cls.xml_raw_text) |
15 | 16 |
|
16 | | - def tearDown(self): |
| 17 | + def test_all(self): |
| 18 | + statement = mybatis_mapper2sql.get_statement(self.mapper, result_type='raw', strip_comments=True) |
| 19 | + print(statement) |
| 20 | + |
| 21 | + def test_base(self): |
| 22 | + self.child_id = 'testBasic' |
17 | 23 | print("============{}============".format(self.child_id)) |
18 | | - self.statement = get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 24 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
19 | 25 | print(self.statement) |
20 | 26 |
|
21 | 27 | def test_parameters(self): |
22 | 28 | self.child_id = 'testParameters' |
| 29 | + print("============{}============".format(self.child_id)) |
| 30 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 31 | + print(self.statement) |
23 | 32 |
|
24 | 33 | def test_include(self): |
25 | 34 | self.child_id = 'testInclude' |
| 35 | + print("============{}============".format(self.child_id)) |
| 36 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 37 | + print(self.statement) |
26 | 38 |
|
27 | 39 | def test_if(self): |
28 | 40 | self.child_id = 'testIf' |
| 41 | + print("============{}============".format(self.child_id)) |
| 42 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 43 | + print(self.statement) |
29 | 44 |
|
30 | 45 | def test_trim(self): |
31 | 46 | self.child_id = 'testTrim' |
| 47 | + print("============{}============".format(self.child_id)) |
| 48 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 49 | + print(self.statement) |
32 | 50 |
|
33 | 51 | def test_where(self): |
34 | 52 | self.child_id = 'testWhere' |
| 53 | + print("============{}============".format(self.child_id)) |
| 54 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 55 | + print(self.statement) |
35 | 56 |
|
36 | 57 | def test_set(self): |
37 | 58 | self.child_id = 'testSet' |
| 59 | + print("============{}============".format(self.child_id)) |
| 60 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 61 | + print(self.statement) |
38 | 62 |
|
39 | 63 | def test_choose(self): |
40 | 64 | self.child_id = 'testChoose' |
| 65 | + print("============{}============".format(self.child_id)) |
| 66 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 67 | + print(self.statement) |
41 | 68 |
|
42 | 69 | def test_foreach(self): |
43 | 70 | self.child_id = 'testForeach' |
| 71 | + print("============{}============".format(self.child_id)) |
| 72 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 73 | + print(self.statement) |
44 | 74 |
|
45 | 75 | def test_bind(self): |
46 | 76 | self.child_id = 'testBind' |
| 77 | + print("============{}============".format(self.child_id)) |
| 78 | + self.statement = mybatis_mapper2sql.get_child_statement(self.mapper, child_id=self.child_id, reindent=True) |
| 79 | + print(self.statement) |
47 | 80 |
|
48 | 81 |
|
49 | 82 | if __name__ == '__main__': |
|
0 commit comments