How to use the nose.tools.assert_raises function in nose

To help you get started, we’ve selected a few nose 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 NYPL-Simplified / circulation / tests / admin / controller / test_collection_registrations.py View on Github external
def test_collection_library_registrations_post(self):
        """Test what might happen POSTing to collection_library_registrations."""
        # First test the failure cases.

        m = self.manager.admin_collection_library_registrations_controller.process_collection_library_registrations

        # Here, the user doesn't have permission to start the
        # registration process.
        self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
        with self.request_context_with_admin("/", method="POST"):
            assert_raises(AdminNotAuthorized, m)
        self.admin.add_role(AdminRole.SYSTEM_ADMIN)

        # The collection ID doesn't correspond to any real collection.
        with self.request_context_with_admin("/", method="POST"):
            flask.request.form = MultiDict([("collection_id", "1234")])
            response = m()
            eq_(MISSING_COLLECTION, response)

        # Pass in a collection ID so that doesn't happen again.
        collection = self._collection()
        collection.external_account_id = "collection url"

        # Oops, the collection doesn't actually support registration.
        form = MultiDict([
            ("collection_id", collection.id),
            ("library_short_name", "not-a-library"),
github mozilla / build-relengapi / relengapi / blueprints / tokenauth / test_tokenstr.py View on Github external
def test_jti2id():
    eq_(tokenstr.jti2id('t12'), 12)
    assert_raises(TypeError, lambda:
                  tokenstr.jti2id('xx'))
    assert_raises(TypeError, lambda:
                  tokenstr.jti2id(None))
github vinzeebreak / road_simulator / tests / tests_layers.py View on Github external
return Background(n_backgrounds=10, path='../ground_pics', width_range=[])
        def instantiate_widthtoolittle():
            return Background(n_backgrounds=10, path='../ground_pics', input_size=(250, 200), width_range=[32, 33])
        def instantiate_nowidth():
            return Background(n_backgrounds=10, path='../ground_pics')
        def call_none():
            d = Crop()
            d.call(None)

        assert_raises(ValueError, instantiate_name_none)
        assert_raises(ValueError, instantiate_nobackgrounds)
        assert_raises(ValueError, instantiate_foldernotexist)
        assert_raises(ValueError, instantiate_folderisfile)
        assert_raises(ValueError, instantiate_nresnegative)
        assert_raises(ValueError, instantiate_inputsizenotuple)
        assert_raises(ValueError, instantiate_inputsizeno2)
        assert_raises(ValueError, instantiate_inputsizenegative)
        assert_raises(ValueError, instantiate_widthnone)
        assert_raises(ValueError, instantiate_widthnotlist)
        assert_raises(ValueError, instantiate_widthemptylist)
        assert_raises(ValueError, instantiate_widthtoolittle)
        assert_raises(ValueError, instantiate_nowidth)
        assert_raises(ValueError, call_none)
github cool-RR / python_toolbox / garlicsim / test_garlicsim / test_general_misc / test_cute_testing / test_raise_assertor.py View on Github external
with RaiseAssertor(Exception):
        raise Exception
    with RaiseAssertor(Exception):
        raise TypeError
    
    def f():
        with RaiseAssertor(ZeroDivisionError):
            raise MyException
    nose.tools.assert_raises(Failure, f)
    with RaiseAssertor(Failure):
        f()
    
    def g():
        with RaiseAssertor(Exception):
            pass
    nose.tools.assert_raises(Failure, g)
    with RaiseAssertor(Failure):
        g()
    
    def h():
        with RaiseAssertor(RuntimeError, 'booga'):
            pass
    nose.tools.assert_raises(Failure, h)
    with RaiseAssertor(Failure):
        h()
    
    with RaiseAssertor(Failure) as raise_assertor:
        assert isinstance(raise_assertor, RaiseAssertor)
        with RaiseAssertor(RuntimeError):
            {}[0]
            
    assert isinstance(raise_assertor.exception, Exception)
github allancaffee / scaly-mongo / tests / unit / test_document.py View on Github external
def should_raise_exception_without_saving(self):
        assert_raises(UnsafeBehaviorError, self.doc.save)
        assert not self.doc.collection.calls('insert')
github rakhimov / scram / scripts / test_fault_tree_generator.py View on Github external
def test_min_max_prob(self):
        """Tests setting of probability factors."""
        assert_raises(FactorError, self.factors.set_min_max_prob, -0.1, 0.5)
        assert_raises(FactorError, self.factors.set_min_max_prob, 1.1, 0.5)
        assert_raises(FactorError, self.factors.set_min_max_prob, 0.1, -0.5)
        assert_raises(FactorError, self.factors.set_min_max_prob, 0.1, 1.5)
        assert_raises(FactorError, self.factors.set_min_max_prob, 0.5, 0.1)
        self.factors.set_min_max_prob(0.1, 0.5)
        assert_equal(0.1, self.factors.min_prob)
        assert_equal(0.5, self.factors.max_prob)
github ErinCall / catsnap / tests / config / test_argument_config.py View on Github external
def test_getitem__when_there_are_no_arguments(self, sys):
        sys.argv = ['catsnap']
        config = ArgumentConfig()
        assert_raises(KeyError, lambda: config['bucket'])
github pycassa / pycassa / tests / test_batch_mutation.py View on Github external
def test_remove_key(self):
        batch = cf.batch()
        batch.insert('1', ROWS['1'])
        batch.remove('1')
        batch.send()
        assert_raises(NotFoundException, cf.get, '1')
github cool-RR / combi / source_py3 / test_combi / test_python_toolbox / test_address_tools / test_resolve.py View on Github external
def test_illegal_input():
    '''Test `resolve` raises exception when given illegal input.'''
    
    nose.tools.assert_raises(Exception,
                             resolve,
                             'asdgfasdgas if 4 else asdfasdfa ')
    
    nose.tools.assert_raises(Exception,
                             resolve,
                             'dgf sdfg sdfga ')
    
    nose.tools.assert_raises(Exception,
                             resolve,
                             '4- ')
github miracle2k / webassets / tests / test_version.py View on Github external
def test_no_cache_attached(self):
        """Test behavior or CacheManifest if no cache is available."""
        manifest = CacheManifest()

        # If no cache is enabled, an error is raised
        self.env.cache = False
        assert_raises(EnvironmentError,
            manifest.remember, self.bundle, self.env, 'the-version')
        assert_raises(EnvironmentError,
            manifest.query, self.bundle, self.env)