Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run_test(dir):
pathlist = Path(dir).glob('*.stan')
nb_test = 0
nb_success = 0
nb_bad = 0
for p in pathlist:
path = str(p)
with open(path, 'r') as fin:
code = fin.read()
try:
pystan.stanc(model_code=code)
nb_test += 1
try:
source = yaps.from_stan(code_file=path)
ast_ = yaps.from_string(source)
stan = yaps.to_stan(ast_)
pystan.stanc(model_code=stan)
nb_success += 1
except (AttributeError, SyntaxError, TypeError, AssertionError, ValueError) as err:
print("FAILED\t", path, err)
except RuntimeError:
nb_success += 1
except (ValueError, RuntimeError):
nb_bad += 1
print("-------------------------")
print("{}% of success ({}/{} valid Stan examples, {} bad examples ignored)".format(
pathlist = Path(dir).glob('*.stan')
nb_test = 0
nb_success = 0
nb_bad = 0
for p in pathlist:
path = str(p)
with open(path, 'r') as fin:
code = fin.read()
try:
pystan.stanc(model_code=code)
nb_test += 1
try:
source = yaps.from_stan(code_file=path)
ast_ = yaps.from_string(source)
stan = yaps.to_stan(ast_)
pystan.stanc(model_code=stan)
nb_success += 1
except (AttributeError, SyntaxError, TypeError, AssertionError, ValueError) as err:
print("FAILED\t", path, err)
except RuntimeError:
nb_success += 1
except (ValueError, RuntimeError):
nb_bad += 1
print("-------------------------")
print("{}% of success ({}/{} valid Stan examples, {} bad examples ignored)".format(
round(nb_success/nb_test * 100, 2), nb_success, nb_test, nb_bad))
def roundtrip(path):
with open(path, 'r') as fin:
code = fin.read()
print(code)
pystan.stanc(model_code=code)
print('--------------------------------')
source = yaps.from_stan(code_file=path)
print(source)
print('--------------------------------')
ast_ = yaps.from_string(source)
code = yaps.to_stan(ast_)
print(code)
print('--------------------------------')
pystan.stanc(model_code=code)