def test_build_string_regex_w_regex_flags(self):
     yara_string = YaraString("test_name",
                              "test[0-9]{2}",
                              str_type="regex",
                              regex_flags="i")
     yara_string.build_string()
     self.assertEqual(yara_string.raw_string,
                      "$test_name = /test[0-9]{2}/i")
 def test_get_yara_string(self):
     yara_string = YaraString("test_name", "test_value")
     yara_string.modifiers = ["ascii", "wide"]
     yara_string.yara_comment = YaraComment()
     yara_string.yara_comment.inline = "test_comment"
     pod_yara_string = yara_string.get_yara_string()
     self.assertEqual(pod_yara_string["name"], "test_name")
     self.assertEqual(pod_yara_string["value"], "test_value")
     self.assertEqual(pod_yara_string["modifiers"], ["ascii", "wide"])
     self.assertEqual(pod_yara_string["comment"]["inline"], "test_comment")
 def test_set_yara_regex_string_with_flags(self):
     yara_string = YaraString(None, None)
     yara_string.set_yara_string({
         "is_anonymous": False,
         "name": "str",
         "str_type": "regex",
         "value": "test regex",
         "regex_flags": "i"
     })
     self.assertEqual(yara_string.is_anonymous, False)
     self.assertEqual(yara_string.name, "str")
     self.assertEqual(yara_string.str_type, "regex")
     self.assertEqual(yara_string.value, "test regex")
     self.assertEqual(yara_string.regex_flags, "i")
 def test_set_yara_string(self):
     yara_string = YaraString(None, None)
     yara_string.set_yara_string({
         "comment": {
             "inline": "example comment"
         },
         "is_anonymous": False,
         "modifiers": ["ascii", "wide"],
         "name": "str",
         "str_type": "text",
         "value": "Named string",
     })
     self.assertEqual(yara_string.yara_comment.inline, "example comment")
     self.assertEqual(yara_string.is_anonymous, False)
     self.assertEqual(yara_string.modifiers, ["ascii", "wide"])
     self.assertEqual(yara_string.name, "str")
     self.assertEqual(yara_string.str_type, "text")
     self.assertEqual(yara_string.value, "Named string")
 def test_set_yara_string_invalid_keys(self):
     yara_string = YaraString(None, None)
     self.assertRaises(KeyError, yara_string.set_yara_string,
                       {"invalid_key": "test"})
 def test_get_yara_string_with_regex_flags(self):
     yara_string = YaraString("test_name", "test_regex", regex_flags="i")
     pod_yara_string = yara_string.get_yara_string()
     self.assertEqual(pod_yara_string["name"], "test_name")
     self.assertEqual(pod_yara_string["value"], "test_regex")
     self.assertEqual(pod_yara_string["regex_flags"], "i")
 def test_build_string_w_newline_after(self):
     yara_string = YaraString("test_name", "test_value", newline_after=True)
     yara_string.build_string()
     self.assertEqual(yara_string.raw_string, '$test_name = "test_value"\n')
 def test_build_string_w_condition(self):
     yara_string = YaraString("test_name", "test_value")
     yara_string.modifiers = ["ascii", "wide"]
     yara_string.build_string()
     self.assertEqual(yara_string.raw_string,
                      '$test_name = "test_value" ascii wide')
 def test_build_string_hex(self):
     yara_string = YaraString("test_name", "AA BB CC DD", str_type="hex")
     yara_string.build_string()
     self.assertEqual(yara_string.raw_string, "$test_name = {AA BB CC DD}")
 def test_build_string_text(self):
     yara_string = YaraString("test_name", "test_value")
     yara_string.build_string()
     self.assertEqual(yara_string.raw_string, '$test_name = "test_value"')
 def test_yara_string_constructor(self):
     yara_string = YaraString("test_name", "test_value")
     self.assertEqual(yara_string.name, "test_name")
     self.assertEqual(yara_string.value, "test_value")
     self.assertEqual(yara_string.str_type, "text")
     self.assertFalse(yara_string.is_anonymous)