def test_fail(self):
        with FailAssert(IllegalConstruction):
            FailChained(self.opt1).kwarg_fun

        with FailAssert(ValueError):
            FailChained(self.opt1).missing_params

        with FailAssert(KeyError):
            chained = Chained(self.opt1)
            f1 = GlobalFuncName('Chained', 'test')
            f2 = GlobalFuncName('SuperChained', 'test')
            # try to set f2 as a dependency of f1
            chained._dependencies[f2] = f1

        with FailAssert(IllegalConstruction):

            class Failer(ChainedProps):
                @args_from_opt()
                @staticmethod
                def failer():
                    pass

        with FailAssert(IllegalConstruction):

            class Failer(ChainedProps):
                @args_from_opt()
                @classmethod
                def failer(cls):
                    pass
    def test_fail(self):
        with FailAssert():
            assert 1 == 2

        with FailAssert(AssertionError):
            assert 1 == 2

        with FailAssert(AssertionError, ValueError):
            assert 1 == 2
            raise ValueError()
 def test_unhandled_exc(self):
     try:
         with FailAssert():
             raise ValueError('pass through failassert')
         raise AssertionError('Should have failed')
     except ValueError:
         pass
 def test_nofail(self):
     try:
         with FailAssert():
             pass
         raise AssertionError('Should have failed')
     except AssertionError:
         pass
    def test_make(self):
        with FailAssert(ValueError):
            Options()

        assert isinstance(Options.make(), Options)
        opt = Options.make([('foo', 'bar')], hej='med')
        assert opt.foo == 'bar'
        assert opt['hej'] == 'med'
    def test_copy(self):
        opt1 = Options.make([('foo', 'bar')],
                            hej='med',
                            dig={'action': 'store_true'})
        opt2 = opt1.copy()

        #TODO copies should copy actions, not values
        with FailAssert(SystemExit):
            with redirect_stderr(StringIO()):
                opt2.parseargs('-d')

        opt2.parseargs('-d', True)
        assert opt2.dig is True
        assert opt1.dig is False
    def test_args_from_opts_decorator(self):
        chained = Chained(self.opt1)
        self.opt1.hej = 'foo'
        self.opt1.med = 'bar'

        assert chained.intmethod('hey') == 'heyfoobar'
        assert chained.firstmethod('hey') == 'heyfoobar'
        with FailAssert(ValueError):
            assert chained.secondmethod('hey') == 'heyfoobar'

        opt2 = self.opt1.copy()
        opt2['dynarg'] = 'dyn'
        chained = Chained(opt2)
        assert chained.secondmethod('hey') == 'dynheybar'
        assert chained.kwargmethod() == 'dynfoobar'
        assert chained.kwargmethod(med='boo') == 'dynfooboo'
        assert chained.nothrill() == 'dynfoobar'
 def test_check_second(self):
     assert self.myfunc3(Dummy(), 1) == 'success'
     with FailAssert():
         self.myfunc3(Dummy(), None)
 def test_simple(self):
     assert self.myfunc(1) == 'success'
     with FailAssert():
         self.myfunc(1.5)