Exemplo n.º 1
0
    def test__get_type(self):
        tests = [
            {"label": "empty string", "text": "", "expect": "blank"},
            {"label": "drop", "text": "DROP TABLE IF EXISTS `my_table`", "expect": "drop"},
            {"label": "create", "text": "CREATE TABLE `my_table` (", "expect": "create"},
            {
                "label": "create close",
                "text": ") ENGINE=InnoDB AUTO_INCREMENT=305 DEFAULT CHARSET=latin1;",
                "expect": "create_close",
            },
            {"label": "column", "text": "`id` int(11) NOT NULL AUTO_INCREMENT,", "expect": "column"},
            {"label": "comment", "text": "-- Table structure for table `company`", "expect": "comment"},
            {"label": "other", "text": "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;", "expect": "other"},
        ]

        for test in tests:
            sl = SchemaLine(text=test["text"])
            self.assertEqual(sl.get_type(), test["expect"])
        return
Exemplo n.º 2
0
    def test__filter(self):
        schema_file = SchemaFile()
        self.assertEqual(schema_file.lines, [])  # Control - no lines
        # filter returns expected
        self.assertEqual(schema_file.filter(["a", "c"]), [])

        schema_line1 = SchemaLine()
        schema_line2 = SchemaLine()
        schema_line3 = SchemaLine()
        schema_line1.type = "a"
        schema_line2.type = "b"
        schema_line3.type = "c"
        schema_file.lines.append(schema_line1)
        schema_file.lines.append(schema_line2)
        schema_file.lines.append(schema_line3)
        self.assertEqual(schema_file.filter(["a", "c"]), [schema_line1, schema_line3])  # filter returns expected
        return