How to use _compute_value method in Slash

Best Python code snippet using slash

test_error.py

Source:test_error.py Github

copy

Full Screen

...14 cls, strings = get_operrcls2('abc %s def %d')15 assert strings == ("abc ", " def ", "")16 assert issubclass(cls, OperationError)17 inst = cls("w_type", strings, "hello", 42)18 assert inst._compute_value(space) == ("abc hello def 42", 16)19 cls2, strings2 = get_operrcls2('a %s b %d c')20 assert cls2 is cls # caching21 assert strings2 == ("a ", " b ", " c")22def test_oefmt(space):23 operr = oefmt("w_type", "abc %s def %d", "foo", 42)24 assert isinstance(operr, OperationError)25 assert operr.w_type == "w_type"26 assert operr._w_value is None27 val = operr._compute_value(space)28 assert val == ("abc foo def 42", 14)29 operr2 = oefmt("w_type2", "a %s b %d c", "bar", 43)30 assert operr2.__class__ is operr.__class__31 operr3 = oefmt("w_type2", "a %s b %s c", "bar", "4b")32 assert operr3.__class__ is not operr.__class__33def test_oefmt_noargs(space):34 operr = oefmt(space.w_AttributeError, "no attribute 'foo'")35 operr.normalize_exception(space)36 val = operr.get_w_value(space)37 assert space.isinstance_w(val, space.w_AttributeError)38 w_repr = space.repr(val)39 assert space.text_w(w_repr) == "AttributeError(\"no attribute 'foo'\")"40def test_oefmt_T(space):41 operr = oefmt(space.w_AttributeError,42 "'%T' object has no attribute '%s'",43 space.wrap('foo'), 'foo')44 assert operr._compute_value(space) == ("'str' object has no attribute 'foo'", 35)45 operr = oefmt("w_type",46 "'%T' object has no attribute '%s'",47 space.wrap('foo'), 'foo')48 assert operr._compute_value(space) == ("'str' object has no attribute 'foo'", 35)49def test_oefmt_N(space):50 operr = oefmt(space.w_AttributeError,51 "'%N' object has no attribute '%s'",52 space.type(space.wrap('foo')), 'foo')53 assert operr._compute_value(space) == ("'str' object has no attribute 'foo'", 35)54 operr = oefmt("w_type",55 "'%N' object has no attribute '%s'",56 space.type(space.wrap('foo')), 'foo')57 assert operr._compute_value(space) == ("'str' object has no attribute 'foo'", 35)58 operr = oefmt(space.w_AttributeError,59 "'%N' object has no attribute '%s'",60 space.wrap('foo'), 'foo')61 assert operr._compute_value(space) == ("'?' object has no attribute 'foo'", 33)62 operr = oefmt("w_type",63 "'%N' object has no attribute '%s'",64 space.wrap('foo'), 'foo')65 assert operr._compute_value(space) == ("'?' object has no attribute 'foo'", 33)66def test_oefmt_R(space):67 operr = oefmt(space.w_ValueError,68 "illegal newline value: %R", space.wrap('foo'))69 assert operr._compute_value(space) == ("illegal newline value: 'foo'", 28)70 operr = oefmt(space.w_ValueError, "illegal newline value: %R",71 space.wrap("'PyLadies'"))72 expected = ("illegal newline value: \"'PyLadies'\"", 35)73 assert operr._compute_value(space) == expected74def test_oefmt_unicode(space):75 operr = oefmt("w_type", "abc %s", u"àèìòù")76 val = operr._compute_value(space)77 assert val == (u"abc àèìòù".encode('utf8'), 9)78def test_oefmt_utf8(space):79 arg = u"àèìòù".encode('utf-8')80 operr = oefmt("w_type", "abc %8", arg)81 val = operr._compute_value(space)82 assert val == (u"abc àèìòù".encode('utf8'), 9)83 #84 # if the arg is a byte string and we specify '%s', then we85 # also get utf-8 encoding. This should be the common case86 # nowadays with utf-8 byte strings being common in the RPython87 # sources of PyPy.88 operr = oefmt("w_type", "abc %s", arg)89 val = operr._compute_value(space)90 assert val == (u"abc àèìòù".encode('utf8'), 9)91 #92 # if the byte string is not valid utf-8, then don't crash93 arg = '\xe9'94 operr = oefmt("w_type", "abc %8", arg)95 val = operr._compute_value(space)96def test_errorstr(space):97 operr = OperationError(space.w_ValueError, space.wrap("message"))98 assert operr.errorstr(space) == "ValueError: message"99 assert operr.errorstr(space, use_repr=True) == (100 "ValueError: ValueError('message')")101 operr = OperationError(space.w_ValueError, space.w_None)102 assert operr.errorstr(space) == "ValueError"103 operr = OperationError(space.w_ValueError,104 space.newtuple([space.wrap(6), space.wrap(7)]))105 assert operr.errorstr(space) == "ValueError: (6, 7)"106 operr = OperationError(space.w_UnicodeDecodeError,107 space.newtuple([108 space.wrap('unicodeescape'),109 space.newbytes(r'\\x'),...

Full Screen

Full Screen

stock_quant.py

Source:stock_quant.py Github

copy

Full Screen

...6 _inherit = 'stock.quant'7 value = fields.Monetary('Value', compute='_compute_value', groups='stock.group_stock_manager')8 currency_id = fields.Many2one('res.currency', compute='_compute_value', groups='stock.group_stock_manager')9 @api.depends('company_id', 'location_id', 'owner_id', 'product_id', 'quantity')10 def _compute_value(self):11 """ For standard and AVCO valuation, compute the current accounting12 valuation of the quants by multiplying the quantity by13 the standard price. Instead for FIFO, use the quantity times the14 average cost (valuation layers are not manage by location so the15 average cost is the same for all location and the valuation field is16 a estimation more than a real value).17 """18 self.currency_id = self.env.company.currency_id19 for quant in self:20 # If the user didn't enter a location yet while enconding a quant.21 if not quant.location_id:22 quant.value = 023 return24 if not quant.location_id._should_be_valued() or\...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful