Exemplo n.º 1
0
    def test6get_match_element_match_context_input_validation(self):
        """Check if an exception is raised, when other classes than MatchContext are used in get_match_element."""
        model_element = VariableByteDataModelElement(self.id_, self.alphabet)
        data = b"abcdefghijklmnopqrstuvwxyz.!?"
        model_element.get_match_element(self.path, DummyMatchContext(data))
        model_element.get_match_element(self.path, MatchContext(data))

        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, MatchElement(None, data, None, None))
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, data)
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, data.decode())
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, 123)
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, 123.22)
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, True)
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, None)
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, [])
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, {"key": MatchContext(data)})
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, set())
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, ())
        self.assertRaises(AttributeError, model_element.get_match_element,
                          self.path, model_element)
Exemplo n.º 2
0
    def test4get_match_element_no_match(self):
        """Parse not matching substring from MatchContext and check if the MatchContext was not changed."""
        data = b""
        match_context = DummyMatchContext(data)
        variable_byte_dme = VariableByteDataModelElement(
            self.id_, self.alphabet)
        match_element = variable_byte_dme.get_match_element(
            self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)

        data = b"!abcdefghijklm nopqrstuvwxyz.!?"
        match_context = DummyMatchContext(data)
        variable_byte_dme = VariableByteDataModelElement(
            self.id_, self.alphabet)
        match_element = variable_byte_dme.get_match_element(
            self.path, match_context)
        self.compare_no_match_results(data, match_element, match_context)
Exemplo n.º 3
0
 def test3match_data_empty(self):
     """The match_context is empty and no match_element is expected."""
     match_context = MatchContext(b'')
     variable_byte_data_model_element = VariableByteDataModelElement(
         'variable', self.alphabet)
     match_element = variable_byte_data_model_element.get_match_element(
         'match', match_context)
     self.assertEqual(match_element, None)
     self.assertEqual(match_context.match_data, b'')
Exemplo n.º 4
0
 def test2match_data_not_starting_with_char_from_alphabet(self):
     """The match_context contains characters of the specified alphabet, but does not start with one."""
     match_context = MatchContext(b'.this sentence started with a dot.')
     variable_byte_data_model_element = VariableByteDataModelElement(
         'variable', self.alphabet)
     match_element = variable_byte_data_model_element.get_match_element(
         'match', match_context)
     self.assertEqual(match_element, None)
     self.assertEqual(match_context.match_data,
                      b'.this sentence started with a dot.')
Exemplo n.º 5
0
 def test1match_data_in_alphabet(self):
     """The match_context contains only characters of the specified alphabet."""
     match_context = MatchContext(
         b'this is a normal sentence in lower case.')
     variable_byte_data_model_element = VariableByteDataModelElement(
         'variable', self.alphabet)
     match_element = variable_byte_data_model_element.get_match_element(
         'match', match_context)
     self.assertEqual(match_element.get_match_string(),
                      b'this is a normal sentence in lower case')
     self.assertEqual(match_context.match_data, b'.')
Exemplo n.º 6
0
 def test3get_match_element_valid_match(self):
     """Parse matching substring from MatchContext and check if the MatchContext was updated with all characters."""
     data = b"abcdefghijklm nopqrstuvwxyz.!?"
     value = b"abcdefghijklm nopqrstuvwxyz"
     match_context = DummyMatchContext(data)
     variable_byte_dme = VariableByteDataModelElement(
         self.id_, self.alphabet)
     match_element = variable_byte_dme.get_match_element(
         self.path, match_context)
     self.compare_match_results(data, match_element, match_context,
                                self.id_, self.path, value, value, None)