<commit_before>import json
import os
import lxml
from lxml.doctestcompare import LXMLOutputChecker, LHTMLOutputChecker
import mock
from corehq.apps.builds.models import CommCareBuild, CommCareBuildConfig, \
    BuildSpec
import difflib


class TestFileMixin(object):

    file_path = ''
    root = os.path.dirname(__file__)

    @property
    def base(self):
        return self.get_base()

    @classmethod
    def get_base(cls):
        return os.path.join(cls.root, *cls.file_path)

    @classmethod
    def get_path(cls, name, ext):
        return os.path.join(cls.get_base(), '%s.%s' % (name, ext))

    @classmethod
    def get_file(cls, name, ext):
        with open(cls.get_path(name, ext)) as f:
            return f.read()

    @classmethod
    def get_json(cls, name):
        return json.loads(cls.get_file(name, 'json'))

    @classmethod
    def get_xml(cls, name):
        return cls.get_file(name, 'xml')

    def assertXmlPartialEqual(self, expected, actual, xpath):
        """
        Extracts a section of XML using the xpath and compares it to the expected

        Extracted XML is placed inside a <partial/> element prior to comparison.
        """<commit_msg>utility write_xml function for authoring tests<commit_after>import json
import os
import lxml
from lxml.doctestcompare import LXMLOutputChecker, LHTMLOutputChecker
import mock
from corehq.apps.builds.models import CommCareBuild, CommCareBuildConfig, \
    BuildSpec
import difflib


class TestFileMixin(object):

    file_path = ''
    root = os.path.dirname(__file__)

    @property
    def base(self):
        return self.get_base()

    @classmethod
    def get_base(cls):
        return os.path.join(cls.root, *cls.file_path)

    @classmethod
    def get_path(cls, name, ext):
        return os.path.join(cls.get_base(), '%s.%s' % (name, ext))

    @classmethod
    def get_file(cls, name, ext):
        with open(cls.get_path(name, ext)) as f:
            return f.read()

    @classmethod
    def write_xml(cls, name, xml):
        with open(cls.get_path(name, 'xml'), 'w') as f:
            return f.write(xml)

    @classmethod
    def get_json(cls, name):
        return json.loads(cls.get_file(name, 'json'))

    @classmethod
    def get_xml(cls, name):
        return cls.get_file(name, 'xml')

    def assertXmlPartialEqual(self, expected, actual, xpath):
        """
        Extracts a section of XML using the xpath and compares it to the expected

        Extracted XML is placed inside a <partial/> element prior to comparison.
        """
{'fraction_non_alphanumeric': 0.10354330708661418, 'fraction_numerical': 0.0, 'mean_word_length': 2.9212962962962963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 13}, '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': '1770613', 'n_tokens_mistral': 830, 'n_tokens_neox': 794, 'n_words': 224}