<commit_before># -*- coding: utf-8 -*-

import unittest2

from openerp.addons.connector.backend import (
        Backend,
        get_backend,
        BACKENDS)
from openerp.addons.connector.connector import Binder
from openerp.addons.connector.unit.mapper import (
                                       Mapper,
                                       ImportMapper,
                                       ExportMapper)
from openerp.addons.connector.unit.backend_adapter import BackendAdapter


class test_backend(unittest2.TestCase):
    """ Test Backend """

    def setUp(self):
        self.service = 'calamitorium'

    def tearDown(self):
        BACKENDS.backends.clear()

    def test_new_backend(self):
        """ Create a backend"""
        version = '1.14'
        backend = Backend(self.service, version=version)
        self.assertEqual(backend.service, self.service)
        self.assertEqual(backend.version, version)

    def test_parent(self):
        """ Bind the backend to a parent backend"""
        version = '1.14'
        backend = Backend(self.service)
        child_backend = Backend(parent=backend, version=version)
        self.assertEqual(child_backend.service, backend.service)

    def test_no_service(self):
        """ Should raise an error because no service or parent is defined"""
        with self.assertRaises(ValueError):
            backend = Backend(version='1.14')

    def test_get_backend(self):
        """ Find a backend """
        backend = Backend(self.service)
        found_ref = get_backend(self.service)
        self.assertEqual(backend, found_ref)

    def test_backend_version(self):
        """ Find a backend with a version """
        parent = Backend(self.service)
        backend = Backend(parent=parent, version='1.14')
        found_ref = get_backend(self.service, version='1.14')
        self.assertEqual(backend, found_ref)


class test_backend_register(unittest2.TestCase):
    """ Test registration of classes on the Backend"""


    def setUp(self):
        self.service = 'calamitorium'
        self.version = '1.14'
        self.parent = Backend(self.service)
        self.backend = Backend(parent=self.parent, version=self.version)

    def tearDown(self):
        BACKENDS.backends.clear()
        self.backend._classes.clear()

    def test_register_class(self):
        class BenderBinder(Binder):
            _model_name = 'res.users'

        self.backend.register_class(BenderBinder)
        ref = self.backend.get_class(Binder, 'res.users')
        self.assertEqual(ref, BenderBinder)

    def test_register_class_decorator(self):
        @self.backend
        class ZoidbergMapper(ExportMapper):
            _model_name = 'res.users'

        ref = self.backend.get_class(ExportMapper, 'res.users')
        self.assertEqual(ref, ZoidbergMapper)

    def test_register_class_parent(self):
        """ It should get the parent's class when no class is defined"""
        @self.parent
        class FryBinder(Binder):
            _model_name = 'res.users'

        ref = self.backend.get_class(Binder, 'res.users')
        self.assertEqual(ref, FryBinder)

    def test_no_register_error(self):
        """ Error when asking for a class and none is found"""
        with self.assertRaises(ValueError):
            ref = self.backend.get_class(BackendAdapter, 'res.users')

    def test_registered_classes_all(self):
        @self.backend
        class LeelaMapper(Mapper):
            _model_name = 'res.users'

        @self.backend
        class FarnsworthBinder(Binder):
            _model_name = 'res.users'

        @self.backend
        class NibblerBackendAdapter(BackendAdapter):
            _model_name = 'res.users'

        classes = list(self.backend.registered_classes())
        self.assertItemsEqual(
                classes,
                [LeelaMapper, FarnsworthBinder, NibblerBackendAdapter])

    def test_registered_classes_filter(self):
        @self.backend
        class LeelaMapper(ExportMapper):
            _model_name = 'res.users'
<commit_msg>[FIX] test, exception changed<commit_after># -*- coding: utf-8 -*-

import unittest2

from openerp.addons.connector.backend import (
        Backend,
        get_backend,
        BACKENDS)
from openerp.addons.connector.connector import Binder
from openerp.addons.connector.unit.mapper import (
                                       Mapper,
                                       ImportMapper,
                                       ExportMapper)
from openerp.addons.connector.unit.backend_adapter import BackendAdapter


class test_backend(unittest2.TestCase):
    """ Test Backend """

    def setUp(self):
        self.service = 'calamitorium'

    def tearDown(self):
        BACKENDS.backends.clear()

    def test_new_backend(self):
        """ Create a backend"""
        version = '1.14'
        backend = Backend(self.service, version=version)
        self.assertEqual(backend.service, self.service)
        self.assertEqual(backend.version, version)

    def test_parent(self):
        """ Bind the backend to a parent backend"""
        version = '1.14'
        backend = Backend(self.service)
        child_backend = Backend(parent=backend, version=version)
        self.assertEqual(child_backend.service, backend.service)

    def test_no_service(self):
        """ Should raise an error because no service or parent is defined"""
        with self.assertRaises(ValueError):
            backend = Backend(version='1.14')

    def test_get_backend(self):
        """ Find a backend """
        backend = Backend(self.service)
        found_ref = get_backend(self.service)
        self.assertEqual(backend, found_ref)

    def test_backend_version(self):
        """ Find a backend with a version """
        parent = Backend(self.service)
        backend = Backend(parent=parent, version='1.14')
        found_ref = get_backend(self.service, version='1.14')
        self.assertEqual(backend, found_ref)


class test_backend_register(unittest2.TestCase):
    """ Test registration of classes on the Backend"""


    def setUp(self):
        self.service = 'calamitorium'
        self.version = '1.14'
        self.parent = Backend(self.service)
        self.backend = Backend(parent=self.parent, version=self.version)

    def tearDown(self):
        BACKENDS.backends.clear()
        self.backend._classes.clear()

    def test_register_class(self):
        class BenderBinder(Binder):
            _model_name = 'res.users'

        self.backend.register_class(BenderBinder)
        ref = self.backend.get_class(Binder, 'res.users')
        self.assertEqual(ref, BenderBinder)

    def test_register_class_decorator(self):
        @self.backend
        class ZoidbergMapper(ExportMapper):
            _model_name = 'res.users'

        ref = self.backend.get_class(ExportMapper, 'res.users')
        self.assertEqual(ref, ZoidbergMapper)

    def test_register_class_parent(self):
        """ It should get the parent's class when no class is defined"""
        @self.parent
        class FryBinder(Binder):
            _model_name = 'res.users'

        ref = self.backend.get_class(Binder, 'res.users')
        self.assertEqual(ref, FryBinder)

    def test_no_register_error(self):
        """ Error when asking for a class and none is found"""
        with self.assertRaises(AssertionError):
            ref = self.backend.get_class(BackendAdapter, 'res.users')

    def test_registered_classes_all(self):
        @self.backend
        class LeelaMapper(Mapper):
            _model_name = 'res.users'

        @self.backend
        class FarnsworthBinder(Binder):
            _model_name = 'res.users'

        @self.backend
        class NibblerBackendAdapter(BackendAdapter):
            _model_name = 'res.users'

        classes = list(self.backend.registered_classes())
        self.assertItemsEqual(
                classes,
                [LeelaMapper, FarnsworthBinder, NibblerBackendAdapter])

    def test_registered_classes_filter(self):
        @self.backend
        class LeelaMapper(ExportMapper):
            _model_name = 'res.users'

{'fraction_non_alphanumeric': 0.09995070248952428, 'fraction_numerical': 0.005422726152329307, 'mean_word_length': 2.435647756138865, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055067', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2256, 'n_words': 469}