def test_parse_cmd_string_5(self): """Verify parse_cmd_string() raises ValueError from incomplete clause. """ filters_string = ("phage.PhageID LIKE Trixie OR") with self.assertRaises(ValueError): parsed_cmd_line = parsing.parse_cmd_string(filters_string)
def test_parse_cmd_string_1(self): filters_string = "phage.PhageID=Trixie AND gene.Notes=Antirepressor" parsed_string = parsing.parse_cmd_string(filters_string) self.assertTrue(len(parsed_string) == 2) self.assertEqual(parsed_string[0], ["phage.PhageID=Trixie"]) self.assertEqual(parsed_string[1], ["gene.Notes=Antirepressor"])
def test_parse_cmd_string_2(self): filters_string = ("phage.PhageID = Trixie OR " "gene.Notes = Antirepressor") parsed_string = parsing.parse_cmd_string(filters_string) self.assertTrue(len(parsed_string) == 1) self.assertTrue(len(parsed_string[0]) == 2) self.assertEqual(parsed_string[0][0], "phage.PhageID = Trixie") self.assertEqual(parsed_string[0][1], "gene.Notes = Antirepressor")
def test_parse_cmd_string_1(self): """Verify parse_cmd_string() recognizes and splits WHERE clauses. """ filters_string = "phage.PhageID=Trixie AND gene.Notes=Antirepressor" parsed_string = parsing.parse_cmd_string(filters_string) self.assertTrue(len(parsed_string) == 1) self.assertEqual(parsed_string[0][0], "phage.PhageID=Trixie") self.assertEqual(parsed_string[0][1], "gene.Notes=Antirepressor")
def test_parse_cmd_string_2(self): """Verify parse_cmd_string() groups ORed WHERE clauses. """ filters_string = ("phage.PhageID = Trixie OR " "gene.Notes = Antirepressor") parsed_string = parsing.parse_cmd_string(filters_string) self.assertTrue(len(parsed_string) == 2) self.assertTrue(len(parsed_string[0]) == 1) self.assertEqual(parsed_string[0][0], "phage.PhageID = Trixie") self.assertEqual(parsed_string[1][0], "gene.Notes = Antirepressor")
def test_parse_cmd_string_4(self): """Verify parse_cmd_string() recognizes LIKE and IS NOT operators. """ filters_string = ("phage.PhageID LIKE Trixie OR " "gene.Notes IS NOT Antirepressor") parsed_string = parsing.parse_cmd_string(filters_string) self.assertTrue(len(parsed_string) == 2) self.assertTrue(len(parsed_string[0]) == 1) self.assertEqual(parsed_string[0][0], "phage.PhageID LIKE Trixie") self.assertEqual(parsed_string[1][0], "gene.Notes IS NOT Antirepressor")
def add(self, filter_string): """Add a MySQL where filter(s) to the Filter object class. :param filter: Formatted MySQL WHERE clause. :type filter: str """ filters = parsing.parse_cmd_string(filter_string) while (filters): and_filters = filters[0] for filter in and_filters: self.and_(filter) filters.pop(0) if filters: self.new_or_()
def test_parse_cmd_filter_5(self): filters_string = ("phage.PhageID LIKE Trixie") parsed_filters = parsing.parse_cmd_string(filters_string)
def test_parse_cmd_string_5(self): filters_string = ("phage.PhageID LIKE Trixie OR") with self.assertRaises(ValueError): parsed_cmd_line = parsing.parse_cmd_string(filters_string)
def test_parse_cmd_filter_3(self): """Verify parse_cmd_string() recognizes LIKE operator. """ filters_string = ("phage.PhageID LIKE Trixie") parsed_filters = parsing.parse_cmd_string(filters_string)