Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testPickleUS(self):
if not set_locale(locale.LC_ALL, 'en_US'):
return
pickled_var = pickle.dumps(currency("12123.45"))
recoverd_var = pickle.loads(pickled_var)
self.assertEqual(recoverd_var.format(), '$12,123.45')
def setUp(self):
self.klist = ObjectList([Column('name', sorted=True)],
[Settable(name='first')])
def _provide_domain_slave_mapper():
from stoqlib.gui.interfaces import IDomainSlaveMapper
from stoqlib.gui.slaves.domainslavemapper import DefaultDomainSlaveMapper
provide_utility(IDomainSlaveMapper, DefaultDomainSlaveMapper(),
replace=True)
def _provide_current_user():
default_store = get_default_store()
user = default_store.find(LoginUser, username=u'admin').one()
assert user
provide_utility(ICurrentUser, user, replace=True)
def _provide_app_info():
from stoqlib.lib.interfaces import IAppInfo
from stoqlib.lib.appinfo import AppInfo
info = AppInfo()
info.set(u"name", u"Stoqlib")
info.set(u"version", u"1.0.0")
provide_utility(IAppInfo, info)
def testGet(self):
self.assertEqual(None, get_utility(IBanana, None))
provide_utility(IBanana, o)
self.assertRaises(TypeError, get_utility, object)
self.assertEqual(get_utility(IBanana), o)
def testVarArgs(self):
f = argcheck(int)(lambda *v: None)
f(1)
f(1, 'str')
f(1, 2, 3)
#self.assertRaises(TypeError, f, 'str')
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))
def testOneArg(self):
f = argcheck(str)(lambda s: None)
f('str')
self.assertRaises(TypeError, f, None)
self.assertRaises(TypeError, f, 1)
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)