How to use the kiwi.argcheck.argcheck function in kiwi

To help you get started, we’ve selected a few kiwi 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 stoq / kiwi / tests / test_argcheck.py View on Github external
def testVarArgs(self):
        f = argcheck(int)(lambda *v: None)
        f(1)
        f(1, 'str')
        f(1, 2, 3)
        #self.assertRaises(TypeError, f, 'str')
github stoq / kiwi / tests / test_argcheck.py View on Github external
def testPercent(self):
        def func(n):
            return n
        func = argcheck(percent)(func)
        self.assertEqual(func(50), 50)
        self.assertEqual(func(50), 50)
        self.assertEqual(func(50.0), 50.0)
        self.assertEqual(func(decimal.Decimal(50)), decimal.Decimal(50))
        self.assertRaises(ValueError, func, -1)
        self.assertRaises(ValueError, func, -1)
        self.assertRaises(ValueError, func, -1.0)
        self.assertRaises(ValueError, func, decimal.Decimal(-1))
        self.assertRaises(ValueError, func, 101)
        self.assertRaises(ValueError, func, 101)
        self.assertRaises(ValueError, func, 101.0)
        self.assertRaises(ValueError, func, decimal.Decimal(101))
github stoq / kiwi / tests / test_argcheck.py View on Github external
def testOneArg(self):
        f = argcheck(str)(lambda s: None)
        f('str')
        self.assertRaises(TypeError, f, None)
        self.assertRaises(TypeError, f, 1)
github stoq / kiwi / tests / test_argcheck.py View on Github external
def testNone(self):
        def func_none(date=None):
            return date
        func_none = argcheck(datetime.datetime)(func_none)
        func_none()
        func_none(None)
        self.assertRaises(TypeError, func_none, True)
        self.assertRaises(TypeError, func_none, date=True)

        def func_none2(s, date=None, date2=None):
            return date
        func_none2 = argcheck(str, datetime.datetime,
                              datetime.datetime)(func_none2)
        func_none2('foo')
        func_none2('bar', None)
        func_none2('baz', None, None)
        func_none2(s='foo')
        func_none2(s='bar', date=None)
        func_none2(s='baz', date=None, date2=None)
        self.assertRaises(TypeError, func_none2, 'noggie', True)
        self.assertRaises(TypeError, func_none2, 'boogie', None, True)
        self.assertRaises(TypeError, func_none2, s='noggie', date2=True)
        self.assertRaises(TypeError, func_none2, s='boogie',
                          date=None, date2=True)
github stoq / kiwi / tests / test_argcheck.py View on Github external
return foo + bar
            method1 = argcheck(int, int)(method1)

            def method2(self, a, b, c, d, e, f, g=0.0):
                return g
            method2 = argcheck(Custom, int, datetime.datetime,
                               int, int, float, float)(method2)

            def method3(self, s, date=None, date2=None):
                return
            method3 = argcheck(str, datetime.datetime,
                               datetime.datetime)(method3)

            def method4(self, n):
                return n
            method4 = argcheck(percent)(method4)

        t = Test()
        self.assertEqual(t.method1(1, 2), 3)
        self.assertRaises(TypeError, t.method1, None, None)
        self.assertEqual(t.method2(Custom(), 2, datetime.datetime.now(),
                                   4, 5, 6.0), 0.0)

        t.method3('foo')
        t.method3('bar', None)
        t.method3('baz', None, None)
        t.method3(s='foo')
        t.method3(s='bar', date=None)
        t.method3(s='baz', date=None, date2=None)
        t.method4(n=0)
        t.method4(n=50)
        t.method4(n=100)
github stoq / stoq / stoqlib / domain / payment / base.py View on Github external
    @argcheck(Decimal, unicode, object)
    def create_credit(self, value, description, till):
        value = abs(value)
        return self._create_till_entry(value, description, till)
github stoq / stoq / stoqlib / domain / payment / methods.py View on Github external
    @argcheck(AbstractPaymentGroup, Decimal, datetime.datetime,
              basestring, Decimal, Till)
    def create_outpayment(self, payment_group, value, due_date=None,
                          description=None, base_value=None, till=None):
        """Creates a new outpayment
        @param payment_group: a L{APaymentGroup} subclass
        @param value: value of payment
        @param due_date: optional, due date of payment
        @param description: optional, description of the payment
        @param base_value: optional
        @param till: optional
        @returns: a L{PaymentAdaptToOutPayment}
        """
        return self.create_payment(IOutPayment, payment_group,
                                   value, due_date,
                                   description, base_value, till)
github stoq / stoq / stoqlib / lib / drivers.py View on Github external
    @argcheck(ASellableItem)
    def add_item(self, item):
        # Do not add services to the coupon
        if isinstance(item, ServiceSellableItem):
            log.info("item %r couldn't added to the coupon, "
                     "since it is a service" % item)
            return
        # GiftCertificates are not printed on the fiscal printer
        # See #2985 for more information.
        elif isinstance(item, GiftCertificateItem):
            return

        sellable = item.sellable
        max_len = self._get_capability("item_description").max_len
        description = sellable.base_sellable_info.description[:max_len]
        unit_desc = ''
        if not sellable.unit:
github stoq / stoq / stoqlib / domain / payment / methods.py View on Github external
    @argcheck(object, Payment)
    def delete_payment(self, iface, payment):
        conn = self.get_connection()
        table = Payment.getAdapterClass(iface)
        table_item = iface(payment)
        table.delete(table_item.id, conn)
        Payment.delete(payment.id, connection=conn)