def test_invalid_expression(self): with self.assertRaises(ValueError): selector.make_expression({"invalid": ["tag1", "tag2"]}) with self.assertRaises(ValueError): selector.make_expression({ "$anyOf": ["tag1", "tag2"], "invalid": "tag3" })
def test_allof_anyof_expression(self): tag1 = "test_tag_1" tag2 = "test_tag_2" tag3 = "test_tag_3" tags_match_1 = [tag1, tag3] tags_match_2 = [tag2, tag3] tags_nomatch_1 = ["other_tag_1", tag3] tags_nomatch_2 = [tag1, "other_tag_2"] tags_nomatch_3 = [tag2, "other_tag_2"] tags_nomatch_4 = [tag2] tags_nomatch_5 = ["other_tag_2"] expression = selector.make_expression( {"$allOf": [ { "$anyOf": [tag1, tag2] }, tag3, ]}) self.assertIsInstance(expression, selector._AllOfExpression) self.assertTrue(expression(tags_match_1)) self.assertTrue(expression(tags_match_2)) self.assertFalse(expression(tags_nomatch_1)) self.assertFalse(expression(tags_nomatch_2)) self.assertFalse(expression(tags_nomatch_3)) self.assertFalse(expression(tags_nomatch_4)) self.assertFalse(expression(tags_nomatch_5)) self.assertFalse(expression([]))
def test_allof_anyof_expression(self): tag1 = "test_tag_1" tag2 = "test_tag_2" tag3 = "test_tag_3" tags_match_1 = [tag1, tag3] tags_match_2 = [tag2, tag3] tags_nomatch_1 = ["other_tag_1", tag3] tags_nomatch_2 = [tag1, "other_tag_2"] tags_nomatch_3 = [tag2, "other_tag_2"] tags_nomatch_4 = [tag2] tags_nomatch_5 = ["other_tag_2"] expression = selector.make_expression({ "$allOf": [ {"$anyOf": [tag1, tag2]}, tag3, ]}) self.assertIsInstance(expression, selector._AllOfExpression) self.assertTrue(expression(tags_match_1)) self.assertTrue(expression(tags_match_2)) self.assertFalse(expression(tags_nomatch_1)) self.assertFalse(expression(tags_nomatch_2)) self.assertFalse(expression(tags_nomatch_3)) self.assertFalse(expression(tags_nomatch_4)) self.assertFalse(expression(tags_nomatch_5)) self.assertFalse(expression([]))
def test_not_expression(self): tag = "test_tag" tags_match = ["other_tag_1"] tags_nomatch = ["other_tag_1", tag] expression = selector.make_expression({"$not": tag}) self.assertIsInstance(expression, selector._NotExpression) self.assertTrue(expression(tags_match)) self.assertTrue(expression([])) self.assertFalse(expression(tags_nomatch))
def test_match_expression(self): tag = "test_tag" tags_with = ["other_tag", tag] tags_without = ["other_tag", "some_tag"] expression = selector.make_expression(tag) self.assertIsInstance(expression, selector._MatchExpression) self.assertTrue(expression(tags_with)) self.assertFalse(expression(tags_without)) self.assertFalse(expression([]))
def test_anyof_expression(self): tag1 = "test_tag" tag2 = "other_tag" tags_match = [tag1, "third_tag"] tags_nomatch = ["third_tag", "some_tag"] expression = selector.make_expression({"$anyOf": [tag1, tag2]}) self.assertIsInstance(expression, selector._AnyOfExpression) self.assertTrue(expression(tags_match)) self.assertFalse(expression(tags_nomatch)) self.assertFalse(expression([]))
def test_match_tag_expression(self): roots = ["dir/subdir1/*.js", "dir/subdir2/test21.*"] test_list = selector._TestList(self.test_file_explorer, roots) expression = selector.make_expression( {"$anyOf": [{"$allOf": ["tag1", "tag2"]}, "tag3", {"$allOf": ["tag5", "tag6"]}]}) def get_tags(test_file): return self.test_file_explorer.jstest_tags(test_file) test_list.match_tag_expression(expression, get_tags) selected, excluded = test_list.get_tests() self.assertEqual(["dir/subdir1/test11.js", "dir/subdir1/test12.js"], selected) self.assertEqual(["dir/subdir2/test21.js"], excluded)
def test_invalid_expression(self): with self.assertRaises(ValueError): selector.make_expression({"invalid": ["tag1", "tag2"]}) with self.assertRaises(ValueError): selector.make_expression({"$anyOf": ["tag1", "tag2"], "invalid": "tag3"})