<commit_before>from openspending.core import db
from openspending.model.dataset import Dataset
from openspending.model.source import Source
from openspending.lib import json

from openspending.importer import CSVImporter

from openspending.tests.base import DatabaseTestCase
from openspending.tests.helpers import fixture_path, make_account


def csvimport_fixture_path(name, path):
    return fixture_path('csv_import/%s/%s' % (name, path))


def csvimport_fixture_file(name, path):
    try:
        fp = open(csvimport_fixture_path(name, path))
    except IOError:
        if name == 'default':
            fp = None
        else:
            fp = csvimport_fixture_file('default', path)

    return fp


def csvimport_fixture(name):
    model_fp = csvimport_fixture_file(name, 'model.json')
    mapping_fp = csvimport_fixture_file(name, 'mapping.json')
    model = json.load(model_fp)
    if mapping_fp:
        model['mapping'] = json.load(mapping_fp)<commit_msg>prefix file path in csvimporter tests with ``file://``.<commit_after>from urllib import urlopen

from openspending.core import db
from openspending.model.dataset import Dataset
from openspending.model.source import Source
from openspending.lib import json

from openspending.importer import CSVImporter

from openspending.tests.base import DatabaseTestCase
from openspending.tests.helpers import fixture_path, make_account


def csvimport_fixture_path(name, path):
    return 'file://' + fixture_path('csv_import/%s/%s' % (name, path))


def csvimport_fixture_file(name, path):
    try:
        fp = urlopen(csvimport_fixture_path(name, path))
    except IOError:
        if name == 'default':
            fp = None
        else:
            fp = csvimport_fixture_file('default', path)

    return fp


def csvimport_fixture(name):
    model_fp = csvimport_fixture_file(name, 'model.json')
    mapping_fp = csvimport_fixture_file(name, 'mapping.json')
    model = json.load(model_fp)
    if mapping_fp:
        model['mapping'] = json.load(mapping_fp)
{'fraction_non_alphanumeric': 0.09212481426448738, 'fraction_numerical': 0.0, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3616350', 'n_tokens_mistral': 626, 'n_tokens_neox': 602, 'n_words': 151}