# L-16 MCS 507 Wed 17 Sep 2023 : factorial50_sympy_test.py

"""
Reworking of the original factorial 50 test
on sympy with Pexpect.
"""

import pexpect
from sage_version_test import sage_version

verbose = False # set to True for more information

V = sage_version()
if(V == None):
    print('Sage not installed?')
else:
    print('version of sage :', V)
    CHILD = pexpect.spawn('/usr/bin/env sage')
    CHILD.expect('sage:')
    if verbose:
        print('opening test script ...')
    # SCRIPT = open('factorial50_sympy.py', 'r')
    SCRIPT = open('factorial50_sympy_assert.py', 'r')
    while True:
        LINE = SCRIPT.readline()
        if(LINE == ""):
            break
        if LINE[0] != '#':
            CMD = LINE[:-1]
            if CMD != '':
                print('executing', CMD)
                CHILD.sendline(CMD)
                CHILD.expect('sage')
                if(CMD[:5] == 'print'):
                    C = CHILD.before.decode()
                    L = C.split(CMD)
                    for line in L:
                        print(line)
                    if verbose:
                        print(L) # L[1].strip())
    CHILD.close()
    print('test passed')
