MCPcopy Index your code
hub / github.com/RustPython/RustPython / eval_equation

Method eval_equation

Lib/test/test_decimal.py:343–469  ·  view source on GitHub ↗
(self, s)

Source from the content-addressed store, hash-verified

341 funct(value)
342
343 def eval_equation(self, s):
344
345 if not TEST_ALL and random.random() < 0.90:
346 return
347
348 self.context.clear_flags()
349
350 try:
351 Sides = s.split('->')
352 L = Sides[0].strip().split()
353 id = L[0]
354 if DEBUG:
355 print("Test ", id, end=" ")
356 funct = L[1].lower()
357 valstemp = L[2:]
358 L = Sides[1].strip().split()
359 ans = L[0]
360 exceptions = L[1:]
361 except (TypeError, AttributeError, IndexError):
362 raise self.decimal.InvalidOperation
363 def FixQuotes(val):
364 val = val.replace("''", 'SingleQuote').replace('""', 'DoubleQuote')
365 val = val.replace("'", '').replace('"', '')
366 val = val.replace('SingleQuote', "'").replace('DoubleQuote', '"')
367 return val
368
369 if id in self.skipped_test_ids:
370 return
371
372 fname = self.NameAdapter.get(funct, funct)
373 if fname == 'rescale':
374 return
375 funct = getattr(self.context, fname)
376 vals = []
377 conglomerate = ''
378 quote = 0
379 theirexceptions = [self.ErrorNames[x.lower()] for x in exceptions]
380
381 for exception in Signals[self.decimal]:
382 self.context.traps[exception] = 1 #Catch these bugs...
383 for exception in theirexceptions:
384 self.context.traps[exception] = 0
385 for i, val in enumerate(valstemp):
386 if val.count("'") % 2 == 1:
387 quote = 1 - quote
388 if quote:
389 conglomerate = conglomerate + ' ' + val
390 continue
391 else:
392 val = conglomerate + val
393 conglomerate = ''
394 v = FixQuotes(val)
395 if fname in ('to_sci_string', 'to_eng_string'):
396 if EXTENDEDERRORTEST:
397 for error in theirexceptions:
398 self.context.traps[error] = 1
399 try:
400 funct(self.context.create_decimal(v))

Callers 1

eval_lineMethod · 0.95

Calls 15

read_unlimitedMethod · 0.95
getexceptionsMethod · 0.95
getattrFunction · 0.85
enumerateFunction · 0.85
strFunction · 0.85
clear_flagsMethod · 0.80
create_decimalMethod · 0.80
printFunction · 0.50
evalFunction · 0.50
randomMethod · 0.45
splitMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected