<commit_before>#Copyright (C) 2013 - The MITRE Corporation
#For license information, see the LICENSE.txt file

#This file has two purposes:
# 1. To provide a rough unit test of libtaxii.messages
# 2. To provide examples of how to use libtaxii.messages


### Contributors ###
#Contributors: If you would like, add your name to the list, alphabetically by last name
#
# <NAME> - <EMAIL>
#

import datetime
import StringIO

from dateutil.tz import tzutc
from lxml import etree

import libtaxii as t
import libtaxii.messages as tm


def message_tests(taxii_message):
    if not isinstance(taxii_message, tm.TAXIIMessage):
        raise ValueError('taxii_message was not an instance of TAXIIMessage')

    print '***** Message type = %s; id = %s' % (taxii_message.message_type, taxii_message.message_id)

    xml_string = taxii_message.to_xml()
    valid = tm.validate_xml(xml_string)
    if not valid:
        raise Exception('\tFailure of test #1 - XML not schema valid')
    msg_from_xml = tm.get_message_from_xml(xml_string)
    dictionary = taxii_message.to_dict()
    msg_from_dict = tm.get_message_from_dict(dictionary)
    if taxii_message != msg_from_xml:
        print '\t Failure of test #2 - running equals w/ debug:'
        taxii_message.__eq__(msg_from_xml, True)
        raise Exception('Test #2 failed - taxii_message != msg_from_xml')

    if taxii_message != msg_from_dict:
        print '\t Failure of test #3 - running equals w/ debug:'
        taxii_message.__eq__(msg_from_dict, True)
        raise Exception('Test #3 failed - taxii_message != msg_from_dict')

    if msg_from_xml != msg_from_dict:
        print '\t Failure of test #4 - running equals w/ debug:'
        msg_from_xml.__eq__(msg_from_dict, True)<commit_msg>Test suite now detects invalid XML<commit_after>#Copyright (C) 2013 - The MITRE Corporation
#For license information, see the LICENSE.txt file

#This file has two purposes:
# 1. To provide a rough unit test of libtaxii.messages
# 2. To provide examples of how to use libtaxii.messages


### Contributors ###
#Contributors: If you would like, add your name to the list, alphabetically by last name
#
# <NAME> - <EMAIL>
#

import datetime
import StringIO

from dateutil.tz import tzutc
from lxml import etree

import libtaxii as t
import libtaxii.messages as tm


def message_tests(taxii_message):
    if not isinstance(taxii_message, tm.TAXIIMessage):
        raise ValueError('taxii_message was not an instance of TAXIIMessage')

    print '***** Message type = %s; id = %s' % (taxii_message.message_type, taxii_message.message_id)

    xml_string = taxii_message.to_xml()
    valid = tm.validate_xml(xml_string)
    if valid is not True:
        raise Exception('\tFailure of test #1 - XML not schema valid: %s' % valid)
    msg_from_xml = tm.get_message_from_xml(xml_string)
    dictionary = taxii_message.to_dict()
    msg_from_dict = tm.get_message_from_dict(dictionary)
    if taxii_message != msg_from_xml:
        print '\t Failure of test #2 - running equals w/ debug:'
        taxii_message.__eq__(msg_from_xml, True)
        raise Exception('Test #2 failed - taxii_message != msg_from_xml')

    if taxii_message != msg_from_dict:
        print '\t Failure of test #3 - running equals w/ debug:'
        taxii_message.__eq__(msg_from_dict, True)
        raise Exception('Test #3 failed - taxii_message != msg_from_dict')

    if msg_from_xml != msg_from_dict:
        print '\t Failure of test #4 - running equals w/ debug:'
        msg_from_xml.__eq__(msg_from_dict, True)
{'fraction_non_alphanumeric': 0.08822695035460992, 'fraction_numerical': 0.006808510638297872, 'mean_word_length': 3.670198675496689, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5899078', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1104, 'n_words': 358}