MCPcopy Index your code
hub / github.com/python/cpython / eval_equation

Method eval_equation

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

Source from the content-addressed store, hash-verified

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

Callers 1

eval_lineMethod · 0.95

Calls 15

read_unlimitedMethod · 0.95
getexceptionsMethod · 0.95
enumerateFunction · 0.85
strFunction · 0.85
clear_flagsMethod · 0.80
create_decimalMethod · 0.80
randomMethod · 0.45
splitMethod · 0.45
stripMethod · 0.45
lowerMethod · 0.45
getMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected