<commit_before>import codecs
import os
import sys

from gears.assets import CircularDependencyError, Asset
from gears.environment import Environment
from gears.finders import FileSystemFinder

from unittest2 import TestCase


TESTS_DIR = os.path.dirname(__file__)
FIXTURES_DIR = os.path.join(TESTS_DIR, 'fixtures', 'assets')


def read(file):
    with codecs.open(file, encoding='utf-8') as f:
        return f.read()


class AssetTests(TestCase):

    def get_fixture_path(self, fixture):
        return os.path.join(FIXTURES_DIR, fixture)

    def get_finder(self, fixture):
        return FileSystemFinder([self.get_fixture_path(fixture)])

    def get_environment(self, fixture):
        environment = Environment(os.path.join(TESTS_DIR, 'static'))
        environment.finders.register(self.get_finder(fixture))
        environment.mimetypes.register_defaults()
        environment.preprocessors.register_defaults()
        return environment

    def get_asset(self, fixture):
        return Asset(*self.get_environment(fixture).find('source.js'))

    def test_circular_dependency(self):
        with self.assertRaises(CircularDependencyError):
            asset = self.get_asset('circular_dependency')

    def test_unicode_support(self):
        output = read(os.path.join(FIXTURES_DIR, 'unicode_support', 'output.js'))
        asset = self.get_asset('unicode_support')
        if sys.version_info < (3, 0):
            asset_output = unicode(asset)
        else:
            asset_output = str(asset)
        self.assertEqual(asset_output, output)<commit_msg>Move test helpers out of asset test case<commit_after>import codecs
import os
import sys

from gears.assets import CircularDependencyError, Asset
from gears.environment import Environment
from gears.finders import FileSystemFinder

from unittest2 import TestCase


TESTS_DIR = os.path.dirname(__file__)
FIXTURES_DIR = os.path.join(TESTS_DIR, 'fixtures', 'assets')


def read(file):
    with codecs.open(file, encoding='utf-8') as f:
        return f.read()


def get_fixture_path(fixture):
    return os.path.join(FIXTURES_DIR, fixture)


def get_finder(fixture):
    return FileSystemFinder([get_fixture_path(fixture)])


def get_environment(fixture):
    environment = Environment(os.path.join(TESTS_DIR, 'static'))
    environment.finders.register(get_finder(fixture))
    environment.register_defaults()
    return environment


def get_asset(fixture):
    return Asset(*get_environment(fixture).find('source.js'))


def get_static_asset(fixture):
    return StaticAsset(*get_environment(fixture).find('source'))


class AssetTests(TestCase):

    def test_circular_dependency(self):
        with self.assertRaises(CircularDependencyError):
            asset = get_asset('circular_dependency')

    def test_unicode_support(self):
        output = read(os.path.join(FIXTURES_DIR, 'unicode_support', 'output.js'))
        asset = get_asset('unicode_support')
        if sys.version_info < (3, 0):
            asset_output = unicode(asset)
        else:
            asset_output = str(asset)
        self.assertEqual(asset_output, output)
{'fraction_non_alphanumeric': 0.10199485199485199, 'fraction_numerical': 0.002574002574002574, 'mean_word_length': 4.014516129032258, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1163059', 'n_tokens_mistral': 962, 'n_tokens_neox': 913, 'n_words': 189}