<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <<EMAIL>>
#
# Distributed under terms of the MIT license.

"""
Tests
"""

import unittest
import yaml
import os.path as op
import os
from copy import deepcopy
from ConfigParser import RawConfigParser
from validator import DataDictValidator
import loaders as ldr

TEST_CONFIG_FILE_PATH = op.join(op.dirname(__file__), "testdata", "test.conf")


class TestProject(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        config_fname = op.basename(TEST_CONFIG_FILE_PATH)
        cls.test_conf_file = op.join(os.getcwd(), config_fname)
        with open(TEST_CONFIG_FILE_PATH, 'r') as f:
            confData = f.read()
        with open(cls.test_conf_file, 'w') as f:
            f.write(confData)
        ldr.CONF_FILE_NAME = config_fname

    @classmethod
    def tearDownClass(cls):
        os.unlink(cls.test_conf_file)

    def setUp(self):
        self.project = ldr.Project(project_name="pysemantic")

    def test_load_dataset(self):
        """
        Test if the project object can load the dataset properly.
        """
        loaded = self.project.load_dataset("iris")
        self.assertItemsEqual(loaded.shape, (150, 5))


class TestConfig(unittest.TestCase):
    """
    Test the configuration management utilities.
    """

    @classmethod
    def setUpClass(cls):<commit_msg>Fix more tests<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <<EMAIL>>
#
# Distributed under terms of the MIT license.

"""
Tests
"""

import unittest
import yaml
import os.path as op
import os
from copy import deepcopy
from ConfigParser import RawConfigParser
from validator import DataDictValidator
import loaders as ldr

TEST_CONFIG_FILE_PATH = op.join(op.dirname(__file__), "testdata", "test.conf")
TEST_DATA_DICT = op.join(op.dirname(__file__), "testdata",
                                               "test_dictionary.yaml")


class TestProject(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        # modify the testdata dict to have absolute paths
        with open(TEST_DATA_DICT, "r") as f:
            testData = yaml.load(f, Loader=yaml.CLoader)
        for name, specs in testData.iteritems():
            path = op.join(op.abspath(op.dirname(__file__)), specs['path'])
            specs['path'] = path
        with open(TEST_DATA_DICT, "w") as f:
            yaml.dump(testData, f, Dumper=yaml.CDumper,
                      default_flow_style=False)

        config_fname = op.basename(TEST_CONFIG_FILE_PATH)
        cls.test_conf_file = op.join(os.getcwd(), config_fname)
        with open(TEST_CONFIG_FILE_PATH, 'r') as f:
            confData = f.read()
        with open(cls.test_conf_file, 'w') as f:
            f.write(confData)
        ldr.CONF_FILE_NAME = config_fname

    @classmethod
    def tearDownClass(cls):
        try:
            # modify the testdata back
            with open(TEST_DATA_DICT, "r") as f:
                testData = yaml.load(f, Loader=yaml.CLoader)
            testData['iris']['path'] = op.join("testdata", "iris.csv")
            testData['person_activity']['path'] = op.join("testdata",
                                                         "person_activity.tsv")
            with open(TEST_DATA_DICT, "w") as f:
                testData = yaml.dump(testData, f, Dumper=yaml.CDumper,
                                     default_flow_style=False)
        finally:
            os.unlink(cls.test_conf_file)

    def setUp(self):
        self.project = ldr.Project(project_name="pysemantic")

    def test_load_dataset(self):
        """
        Test if the project object can load the dataset properly.
        """
        loaded = self.project.load_dataset("iris")
        self.assertItemsEqual(loaded.shape, (150, 5))


class TestConfig(unittest.TestCase):
    """
    Test the configuration management utilities.
    """

    @classmethod
    def setUpClass(cls):
{'fraction_non_alphanumeric': 0.11061285500747384, 'fraction_numerical': 0.004982561036372696, 'mean_word_length': 2.537444933920705, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4450131', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1225, 'n_words': 288}