<commit_before>import unittest
import os

import factory

from cumulusci.utils import temporary_dir
from cumulusci.tasks.bulkdata.tests.test_bulkdata import _make_task
from cumulusci.tasks.bulkdata.tests.dummy_data_factory import GenerateDummyData, Contact
from cumulusci.tasks.bulkdata import factory_utils


class TestFactoryUtils(unittest.TestCase):
    def test_factory(self):
        mapping_file = os.path.join(os.path.dirname(__file__), "mapping_v2.yml")

        with temporary_dir() as d:
            tmp_db_path = os.path.join(d, "temp.db")
            dburl = "sqlite:///" + tmp_db_path
            task = _make_task(
                GenerateDummyData,
                {
                    "options": {
                        "num_records": 10,
                        "mapping": mapping_file,
                        "database_url": dburl,
                    }
                },
            )
            task()


class TestAdder(unittest.TestCase):
    def test_adder(self):
        a = factory_utils.Adder(10)
        b = a(20)
        assert b == 30
        c = a(0)
        assert c == 30
        d = a(-5)
        assert d == 25
        a.reset(3)
        assert a(0) == 3


class TestFactories(unittest.TestCase):
    def test_factories(self):
        class Broken(factory.alchemy.SQLAlchemyModelFactory):
            class Meta:
                model = "xyzzy"

        try:
            factory_utils.Factories(None, {}, {"A": Contact, "B": Broken})
        except KeyError as e:
            assert "not found" in repr(e)
            return
        assert False, "Should not get to this point"<commit_msg>Use assertRaises.<commit_after>import unittest
import os

import factory

from cumulusci.utils import temporary_dir
from cumulusci.tasks.bulkdata.tests.test_bulkdata import _make_task
from cumulusci.tasks.bulkdata.tests.dummy_data_factory import GenerateDummyData, Contact
from cumulusci.tasks.bulkdata import factory_utils


class TestFactoryUtils(unittest.TestCase):
    def test_factory(self):
        mapping_file = os.path.join(os.path.dirname(__file__), "mapping_v2.yml")

        with temporary_dir() as d:
            tmp_db_path = os.path.join(d, "temp.db")
            dburl = "sqlite:///" + tmp_db_path
            task = _make_task(
                GenerateDummyData,
                {
                    "options": {
                        "num_records": 10,
                        "mapping": mapping_file,
                        "database_url": dburl,
                    }
                },
            )
            task()


class TestAdder(unittest.TestCase):
    def test_adder(self):
        a = factory_utils.Adder(10)
        b = a(20)
        assert b == 30
        c = a(0)
        assert c == 30
        d = a(-5)
        assert d == 25
        a.reset(3)
        assert a(0) == 3


class TestFactories(unittest.TestCase):
    def test_factories(self):
        class Broken(factory.alchemy.SQLAlchemyModelFactory):
            class Meta:
                model = "xyzzy"

        with self.assertRaises(KeyError):
            factory_utils.Factories(None, {}, {"A": Contact, "B": Broken})
{'fraction_non_alphanumeric': 0.09793322734499205, 'fraction_numerical': 0.011446740858505564, 'mean_word_length': 1.811438784629133, 'pattern_counts': {'":': 12, '<': 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': '3828801', 'n_tokens_mistral': 969, 'n_tokens_neox': 907, 'n_words': 203}