How to use the nose2.compat.unittest.TestCase function in nose2

To help you get started, we’ve selected a few nose2 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 mulhod / reviewer_experience_prediction / tests / test_datasets.py View on Github external
# place precision
            ]
        for bin_ranges in bin_ranges_invalid:
            assert_raises(ValueError, validate_bin_ranges, bin_ranges)

    def test_validate_bin_ranges_valid():
        """
        Test the `validate_bin_ranges` function given valid
        `bin_ranges` values.
        """

        bin_ranges_valid = [(0.0, 90.1), (90.2, 104.5), (104.6, 150.9)]
        assert_equal(validate_bin_ranges(bin_ranges_valid), None)


class ComputeLabelValueTestCase(unittest.TestCase):
    """
    Test the `compute_label_value` function.
    """

    def test_compute_label_value_negative(self):
        """
        Test the `compute_label_value` function with a negative input
        value.
        """

        value = -1.0
        label = "total_game_hours"
        with self.assertRaises(ValueError):
            compute_label_value(value, label)

    def test_compute_label_value_kwargs_conflict(self):
github davoclavo / vinepy / tests / test_vinepy.py View on Github external
# Decorator tests

    def test_vine_json(self):
        pass

    def test_ensure_ownership(self):
        pass

    def test_chained(self):
        pass

    def test_inject_post(self):
        pass


class TestUtils(unittest.TestCase):
    short_id = 'OjunvOxTpZ5'
    long_id = 1167619641938518016

    def test_post_long_id(self):
        long_id = vinepy.post_long_id(self.short_id)
        self.assertEqual(self.long_id, long_id)

    def test_post_short_id(self):
        short_id = vinepy.post_short_id(self.long_id)
        self.assertEqual(self.short_id, short_id)
github davoclavo / vinepy / tests / test_vinepy.py View on Github external
user_id = 948731399408640000

        with my_vcr.use_cassette('unfollow_notifications.yml') as cassette:
            api.unfollow_notifications(user_id=user_id)
            user = api.get_user(user_id=user_id)
            self.assertTrue(user.is_following())
            self.assertFalse(user.is_notifying())

        with my_vcr.use_cassette('follow_notifications.yml') as cassette:
            api.follow_notifications(user_id=user_id)
            user = api.get_user(user_id=user_id)
            self.assertTrue(user.is_following())
            self.assertTrue(user.is_notifying())


class TestModel(unittest.TestCase):
    # Model method tests

    def test_model_from_json(self):
        mock_json = {'id': 1,
                     'from_json': 'something'
                     }
        model = vinepy.Model.from_json(mock_json)
        self.assertEqual(model['id'], mock_json['id'])
        # Does not replace an existing key
        self.assertNotEqual(model.from_json, mock_json['from_json'])

        # classname + 'Id' replaces 'id' key
        mock_json['modelId'] = 2
        model = vinepy.Model.from_json(mock_json)
        self.assertEqual(model.id, mock_json['modelId'])
github mulhod / reviewer_experience_prediction / tests / test_src.py View on Github external
VALID_GAMES,
                 TIME_LABELS,
                 LEARNER_DICT,
                 get_game_files,
                 FRIENDS_LABELS,
                 HELPFUL_LABELS,
                 LEARNER_DICT_KEYS,
                 parse_games_string,
                 DEFAULT_PARAM_GRIDS,
                 ACHIEVEMENTS_LABELS,
                 parse_learners_string,
                 find_default_param_grid,
                 parse_non_nlp_features_string)


class GetGameFilesTestCase(unittest.TestCase):
    """
    Test the `get_game_files` method.
    """

    @staticmethod
    def test_get_game_files_empty_games_string():
        """
        Test the `get_game_files` function given an empty games string.
        """

        # Test with an empty string
        assert_raises(ValueError, get_game_files, '')

    @staticmethod
    def test_get_game_files_sample_file_only():
        """
github mulhod / reviewer_experience_prediction / tests / test_src.py View on Github external
"""
        Use invalid parameter values to test `parse_learners_string`.
        """

        # Test some combinations of invalid (and possibly valid)
        # learner-types
        fake_and_real_names = (self.learners
                               + ['perceptron', 'multinomialnb', 'MNB', ''])
        np.random.shuffle(fake_and_real_names)
        for i in range(len(fake_and_real_names)):
            if set(self.learners).issuperset(fake_and_real_names[:i]): continue
            with self.assertRaises(ValueError):
                parse_learners_string(','.join(fake_and_real_names[:i]))


class ParseNonNLPFeaturesStringTestCase(unittest.TestCase):
    """
    Tests for the `parse_non_nlp_features_string` function.
    """

    labels = set(LABELS)
    label_groups = dict(TIME_LABELS=set(TIME_LABELS),
                        FRIENDS_LABELS=set(FRIENDS_LABELS),
                        HELPFUL_LABELS=set(HELPFUL_LABELS),
                        ACHIEVEMENTS_LABELS=set(ACHIEVEMENTS_LABELS),
                        OTHER=set([label for label in LABELS
                                   if not label in chain(TIME_LABELS,
                                                         FRIENDS_LABELS,
                                                         HELPFUL_LABELS,
                                                         ACHIEVEMENTS_LABELS)]))

    def test_parse_non_nlp_features_string_valid(self):
github opengisch / qgis_setting_manager / qgis_testing / __init__.py View on Github external
# This will get replaced with a git SHA1 when you do a git archive

__revision__ = ':%H$'

import os
import sys
import difflib
import functools

from PyQt4.QtCore import QVariant
from qgis.core import QgsApplication, QgsFeatureRequest, QgsVectorLayer
from nose2.compat import unittest

# Get a backup, we will patch this one later
_TestCase = unittest.TestCase


class TestCase(_TestCase):

    def assertLayersEqual(self, layer_expected, layer_result, **kwargs):
        """
        :param layer_expected: The first layer to compare
        :param layer_result: The second layer to compare
        :param request: Optional, A feature request. This can be used to specify
                        an order by clause to make sure features are compared in
                        a given sequence if they don't match by default.
        :keyword compare: A map of comparison options. e.g.
                         { fields: { a: skip, b: { precision: 2 }, geometry: { precision: 5 } }
                         { fields: { __all__: cast( str ) } }
        """
github mulhod / reviewer_experience_prediction / tests / test_experiments.py View on Github external
if len(exp_data.test_set):
                samples.extend(exp_data.test_set)
            if exp_data.training_set:
                samples.extend(chain(*exp_data.training_set))
            if exp_data.grid_search_set:
                samples.extend(chain(*exp_data.grid_search_set))
            sample_counter = Counter(samples)
            assert all(sample_counter[_id] == 1 for _id in sample_counter)

            # The `sampling` attribute should reflect the value passed
            # in as the parameter value (or the default value)
            assert_equal(_kwargs.get('sampling', 'stratified'),
                         exp_data.sampling)


class CVConfigTestCase(unittest.TestCase):
    """
    Test the `CVConfig` class.
    """

    def setUp(self):
        try:
            self.db = connect_to_db('localhost', 37017)
        except AutoReconnect as e:
            raise ConnectionFailure('Could not connect to MongoDB client. Make'
                                    'sure a tunnel is set up (or some other '
                                    'method is used) before running the '
                                    'tests.')
        self.prediction_label = 'total_game_hours'
        self.output_path = join(this_dir, 'test_output')
        if exists(self.output_path):
            rmtree(self.output_path)
github davoclavo / vinepy / tests / test_vinepy.py View on Github external
import vcr
import vinepy

from nose2.compat import unittest


my_vcr = vcr.VCR(
    cassette_library_dir='fixtures/cassettes',
    record_mode='once',
    match_on=['uri', 'method'],
    # record_mode = 'all' # Re-record cassettes
)


class TestAPI(unittest.TestCase):

    @my_vcr.use_cassette('login.yml')
    @classmethod
    def setUp(cls):
        cls.vine_name = 'Bob Testy'
        cls.vine_email = 'bobtesty@suremail.info'
        cls.vine_password = 'password'
        cls.api = vinepy.API(
            username=cls.vine_email, password=cls.vine_password)

    @my_vcr.use_cassette('signup.yml')
    def test_signup(self):
        api = vinepy.API().signup(
            username=self.vine_name, email=self.vine_email, password=self.vine_password)
        self.assertEqual(api.username, self.vine_name)
github mulhod / reviewer_experience_prediction / tests / test_experiments.py View on Github external
from src.mongodb import connect_to_db
from src.datasets import validate_bin_ranges
from src.experiments import (make_cursor,
                             get_all_features,
                             get_label_in_doc,
                             ExperimentalData)
from src import (LABELS,
                 LEARNER_DICT,
                 LEARNER_DICT_KEYS,
                 DEFAULT_PARAM_GRIDS,
                 OBJ_FUNC_ABBRS_DICT,
                 parse_non_nlp_features_string)

this_dir = dirname(realpath(__file__))

class MakeCursorTestCase(unittest.TestCase):
    """
    Test the `make_cursor` function.
    """

    db = None
    ids = ['5690a60fe76db81bef5c46f8', '5690a60fe76db81bef5c275f',
           '5690a60fe76db81bef5c49e9', '5690a60fe76db81bef5c3a67',
           '5690a60fe76db81bef5c2d26', '5690a60fe76db81bef5c2756',
           '5690a60fe76db81bef5c2bc9', '5690a60fe76db81bef5c3ab1',
           '5690a60fe76db81bef5c3a71', '5690a60fe76db81bef5c2edf',
           '5690a60fe76db81bef5c2f72', '5690a60fe76db81bef5c4305',
           '5690a60fe76db81bef5c3ee9', '5690a60fe76db81bef5c4ab6',
           '5690a60fe76db81bef5c43cf', '5690a60fe76db81bef5c47f1',
           '5690a60fe76db81bef5c2b0b', '5690a60fe76db81bef5c4920',
           '5690a60fe76db81bef5c49d9', '5690a60fe76db81bef5c3048',
           '5690a60fe76db81bef5c4057', '5690a60fe76db81bef5c3902',
github davoclavo / vinepy / tests / test_vinepy.py View on Github external
import vcr
import vinepy

from nose2.compat import unittest


my_vcr = vcr.VCR(
    cassette_library_dir='fixtures/cassettes',
    record_mode='once',
    match_on=['uri', 'method'],
    # record_mode = 'all' # Re-record cassettes
)


class TestAPI(unittest.TestCase):

    @my_vcr.use_cassette('login.yml')
    @classmethod
    def setUp(cls):
        cls.vine_name = 'Bob Testy'
        cls.vine_email = 'bobtesty@suremail.info'
        cls.vine_password = 'password'
        cls.api = vinepy.API(
            username=cls.vine_email, password=cls.vine_password)

    @my_vcr.use_cassette('signup.yml')
    def test_signup(self):
        api = vinepy.API().signup(
            username=self.vine_name, email=self.vine_email, password=self.vine_password)
        self.assertEqual(api.username, self.vine_name)