# L-16 MCS 507 Wed 27 Sep 2023 : sage_version_test.py

"""
We test if sage is installed and return the version.
"""

import pexpect

def sage_version():
    """
    Returns a string containing sage version
    and release date or None if sage cannot
    be found at the execution path.
    """
    try:
        child = pexpect.spawn('/usr/bin/env sage')
    except:
        return None
    child.expect('sage')
    first = child.before.decode()
    lines = first.split('version')
    return lines[1][1:4]

if __name__ == "__main__":
    print('version of SageMath :', sage_version())
