def test7get_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 = OptionalMatchModelElement(
            self.id_, DummyFixedDataModelElement(self.fixed_id,
                                                 self.fixed_data))
        data = b"fixed data"
        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)
 def test1_match_element_expected(self):
     """Because of the simplicity of the FixedDataModelElement it is used to test possible outcomes of this class."""
     match_context = MatchContext(b'This is some String.')
     fixed_data_model_element = FixedDataModelElement('fixed', b'This')
     optional_match_model_element = OptionalMatchModelElement(
         'optional', fixed_data_model_element)
     self.assertEqual(
         optional_match_model_element.get_match_element(
             'match', match_context).get_match_string(), b'This')
     self.assertEqual(match_context.match_data, b' is some String.')
 def test2_match_element_empty(self):
     """An Empty MatchElement is expected, due to not finding the fixed String. The MatchContext must not be changed."""
     match_context = MatchContext(b'Another String.')
     fixed_data_model_element = FixedDataModelElement('fixed', b'This')
     optional_match_model_element = OptionalMatchModelElement(
         'optional', fixed_data_model_element)
     self.assertEqual(
         optional_match_model_element.get_match_element(
             'match', match_context).get_match_string(), '')
     self.assertEqual(match_context.match_data, b'Another String.')
    def test4get_match_element_no_match(self):
        """Parse not matching substring from MatchContext and check if the MatchContext was not changed."""
        optional_match = OptionalMatchModelElement(
            self.id_, DummyFixedDataModelElement(self.fixed_id,
                                                 self.fixed_data))
        data = b""
        match_context = DummyMatchContext(data)
        match_element = optional_match.get_match_element(
            self.path, match_context)
        self.compare_match_results(data, match_element, match_context,
                                   self.id_, self.path, data, None, None)

        data = b"other fixed string"
        value = b""
        match_context = DummyMatchContext(data)
        match_element = optional_match.get_match_element(
            self.path, match_context)
        self.compare_match_results(data, match_element, match_context,
                                   self.id_, self.path, value, None, None)
 def test3get_match_element_valid_match(self):
     """Parse matching substring from MatchContext and check if the MatchContext was updated with all characters."""
     data = b"fixed data string."
     value = self.fixed_data
     match_context = DummyMatchContext(data)
     fixed_dme = DummyFixedDataModelElement(self.fixed_id, self.fixed_data)
     optional_match = OptionalMatchModelElement(self.id_, fixed_dme)
     match_element = optional_match.get_match_element(
         self.path, match_context)
     self.compare_match_results(
         data, match_element, match_context, self.id_, self.path, value,
         value, [
             fixed_dme.get_match_element("%s/%s" % (self.path, self.id_),
                                         DummyMatchContext(data))
         ])