How to use the unittest2.TestCase function in unittest2

To help you get started, we’ve selected a few unittest2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dexonline / dexonline / tools / functests / test_login.py View on Github external
# This prints a bunch of text/password controls, but only ONE CheckboxControl
def edit_account(br, nick, password, new_password, new_password2, name, email, design, pref_st):
    br.open(URL_BASE + '/preferinte').read()
    br.select_form(name='accountForm')
    if nick: br['nick'] = nick
    if password: br['curPass'] = password
    if new_password: br['newPass'] = new_password
    if new_password2: br['newPass2'] = new_password2
    if name: br['name'] = name
    if email: br['email'] = email
    if design: br['skin'] = [design]
    if pref_st is not None: br.find_control('userPrefs[]').items[0].selected = pref_st
    resp = br.submit()
    return resp

class LoginTest(unittest.TestCase):

    def test_register_bad_info(self):
        br = mechanize.Browser()
        resp = create_account(br, '', '', '')
        html = resp.read()
        self.assertIn('Trebuie să vă alegeți un nume de cont', html)

        resp = create_account(br, 'john', '', '')
        html = resp.read()
        self.assertIn('Trebuie să vă alegeți o parolă', html)

        resp = create_account(br, 'john', 'john@john.com', 'password', 'mismatched password')
        html = resp.read()
        self.assertIn('Parolele nu coincid', html)

        resp = create_account(br, 'vasile', 'john@john.com', 'password')
github BigBrotherBot / big-brother-bot / tests / core / parsers / test_iourt41.py View on Github external
import b3
import logging
import unittest2 as unittest

from mockito import mock, when, any as anything, verify
from mock import Mock, patch, ANY
from b3.clients import Client
from b3.config import XmlConfigParser
from b3.events import Event
from b3.fake import FakeClient
from b3.parsers.iourt41 import Iourt41Parser

log = logging.getLogger("test")
log.setLevel(logging.INFO)

class Iourt41TestCase(unittest.TestCase):
    """
    Test case that is suitable for testing iourt41 parser specific features
    """
    @classmethod
    def setUpClass(cls):
        from b3.parsers.q3a.abstractParser import AbstractParser
        from b3.fake import FakeConsole
        AbstractParser.__bases__ = (FakeConsole,)
        # Now parser inheritance hierarchy is :
        # Iourt41Parser -> AbstractParser -> FakeConsole -> Parser

    def setUp(self):
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString("""
                
github gorakhargosh / mom / tests / test_mom_functional.py View on Github external
self.assertRaises(TypeError, omits, 0, 4)

class Test__contains(unittest2.TestCase):
    def test__contains_value(self):
        self.assertTrue(_contains_fallback(range(4), 3))
        self.assertFalse(_contains_fallback(range(4), 43))
        self.assertTrue(_contains_fallback({"a": 4, "b": 5}, "a"))
        self.assertFalse(_contains_fallback({"a": 4, "b": 5}, "c"))

    def test_TypeError_when_not_iterable(self):
        self.assertRaises(TypeError, _contains_fallback, None, 4)
        self.assertRaises(TypeError, _contains_fallback, True, 4)
        self.assertRaises(TypeError, _contains_fallback, 0, 4)

# Unique, union, difference, and without tests.
class Test_difference(unittest2.TestCase):
    def test_difference(self):
        self.assertEqual(difference(range(1, 6), [5, 2, 10]), [1, 3, 4])
        self.assertEqual(difference("abcdefg", "abc"), list("defg"))
        self.assertEqual(difference("abcdefg", "xyz"), list("abcdefg"))

    def test_TypeError_when_not_iterable(self):
        self.assertRaises(TypeError, difference, None, None)
        self.assertRaises(TypeError, difference, None, True)
        self.assertRaises(TypeError, difference, None, 0)
        self.assertRaises(TypeError, difference, 0, None)
        self.assertRaises(TypeError, difference, 0, True)
        self.assertRaises(TypeError, difference, 0, 0)

class Test_idifference(unittest2.TestCase):
    def test_idifference(self):
        self.assertEqual(list(idifference(range(1, 6), [5, 2, 10])), [1, 3, 4])
github ets-labs / python-dependency-injector / tests / unit / providers / test_configuration_py2_py3.py View on Github external
self.config.from_ini(self.config_file)

        self.assertEqual(
            self.config(),
            {
                'section1': {
                    'value1': 'test-value',
                },
            },
        )
        self.assertEqual(self.config.section1(), {'value1': 'test-value'})
        self.assertEqual(self.config.section1.value1(), 'test-value')



class ConfigFromYamlTests(unittest.TestCase):

    def setUp(self):
        self.config = providers.Configuration(name='config')

        _, self.config_file_1 = tempfile.mkstemp()
        with open(self.config_file_1, 'w') as config_file:
            config_file.write(
                'section1:\n'
                '  value1: 1\n'
                '\n'
                'section2:\n'
                '  value2: 2\n'
            )

        _, self.config_file_2 = tempfile.mkstemp()
        with open(self.config_file_2, 'w') as config_file:
github chembl / chembl_webresource_client / chembl_webresource_client / test_utils.py View on Github external
17 31  1  6
 16 32  1  6
 19 18  1  0
  7  4  1  0
 10 12  2  0
 17 16  1  0
 28 30  1  0
M  END
> 
CHEMBL1200735


$$$$
'''

class TestSequenceFunctions(unittest.TestCase):

    def test_resolve(self):

        ret = resolve('viagra')
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL1737')

        ret = resolve('gleevec')
        self.assertEqual(len(ret), 2)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')
        self.assertEqual(ret[1]['molecule_chembl_id'], 'CHEMBL1642')

        ret = resolve('gleevec', single_result=True)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')
github samgiles / slumber / tests / utils.py View on Github external
# -*- coding: utf-8 -*-
import sys

import unittest2 as unittest
import slumber


class UtilsTestCase(unittest.TestCase):

    def test_copy_kwargs(self):
        self.assertEqual({ 'x': 1 }, slumber.copy_kwargs({ 'x': 1 }))

    def test_url_join_http(self):
        self.assertEqual(slumber.url_join("http://example.com/"), "http://example.com/")
        self.assertEqual(slumber.url_join("http://example.com/", "test"), "http://example.com/test")
        self.assertEqual(slumber.url_join("http://example.com/", "test", "example"), "http://example.com/test/example")

        self.assertEqual(slumber.url_join("http://example.com"), "http://example.com/")
        self.assertEqual(slumber.url_join("http://example.com", "test"), "http://example.com/test")
        self.assertEqual(slumber.url_join("http://example.com", "test", "example"), "http://example.com/test/example")

    def test_url_join_https(self):
        self.assertEqual(slumber.url_join("https://example.com/"), "https://example.com/")
        self.assertEqual(slumber.url_join("https://example.com/", "test"), "https://example.com/test")
github cloudendpoints / endpoints-management-python / test / test_client.py View on Github external
"flushIntervalMs": 2000
    },
    "quotaAggregatorConfig": {
       "cacheEntries": 10,
       "expirationMs": 2000,
       "flushIntervalMs": 1000
    },
    "reportAggregatorConfig": {
       "cacheEntries": 10,
       "flushIntervalMs": 1000
    }
}
"""


class TestEnvironmentLoader(unittest2.TestCase):
    SERVICE_NAME = u'environment-loader'

    def setUp(self):
        json_fd = tempfile.NamedTemporaryFile(delete=False)
        with json_fd as f:
            f.write(_TEST_CONFIG.encode('ascii'))
        self._config_file = json_fd.name
        os.environ[client.CONFIG_VAR] = self._config_file

    def tearDown(self):
        if os.path.exists(self._config_file):
            os.remove(self._config_file)

    @mock.patch(u"endpoints_management.control.client.ReportOptions", autospec=True)
    @mock.patch(u"endpoints_management.control.client.QuotaOptions", autospec=True)
    @mock.patch(u"endpoints_management.control.client.CheckOptions", autospec=True)
github ets-labs / python-dependency-injector / tests / test_catalogs.py View on Github external
self.assertFalse(CatalogA.p11.is_overridden)
        self.assertFalse(CatalogA.p12.is_overridden)


class CatalogModuleBackwardCompatibility(unittest.TestCase):
    """Backward compatibility test of catalog module."""

    def test_import_catalog(self):
        """Test that module `catalog` is the same as `catalogs`."""
        from dependency_injector import catalog
        from dependency_injector import catalogs

        self.assertIs(catalog, catalogs)


class TestCatalogWithProvidingCallbacks(unittest.TestCase):
    """Catalog with providing callback tests."""

    def test_concept(self):
        """Test concept."""
        class UsersService(object):
            """Users service, that has dependency on database."""

        class AuthService(object):
            """Auth service, that has dependencies on users service."""

            def __init__(self, users_service):
                """Initializer."""
                self.users_service = users_service

        class Services(catalogs.DeclarativeCatalog):
            """Catalog of service providers."""
github JohnVinyard / zounds / zounds / loudness / test_loudness.py View on Github external
import unittest2
from .loudness import mu_law, inverse_mu_law, inverse_one_hot, instance_scale
import numpy as np


class TestLoudness(unittest2.TestCase):
    def test_can_invert_mu_law(self):
        a = np.random.normal(0, 1, (100, 4))
        adjusted = mu_law(a)
        inverted = inverse_mu_law(adjusted)
        np.testing.assert_allclose(a, inverted)


class TestInverseOneHot(unittest2.TestCase):
    def test_inverse_one_hot_1d_produces_scalar(self):
        arr = np.zeros(10)
        arr[5] = 1
        x = inverse_one_hot(arr)
        self.assertEqual((), x.shape)

    def test_inverse_one_hot_2d_produces_1d_output(self):
        arr = np.eye(10)
github googleapis / oauth2client / tests / contrib / test_multistore_file.py View on Github external
key3: val3,
        }
        tuple_key = multistore_file._dict_to_tuple_key(test_dict)

        # the resulting key should be naturally sorted
        expected_output = (
            (key2, val2),
            (key3, val3),
            (key1, val1),
        )
        self.assertTupleEqual(expected_output, tuple_key)
        # check we get the original dictionary back
        self.assertDictEqual(test_dict, dict(tuple_key))


class MultistoreFileTests(unittest2.TestCase):

    def tearDown(self):
        try:
            os.unlink(FILENAME)
        except OSError:
            pass

    def setUp(self):
        try:
            os.unlink(FILENAME)
        except OSError:
            pass

    def _create_test_credentials(self, client_id='some_client_id',
                                 expiration=None):
        access_token = 'foo'