from a1 import *

TAGS = ['Author', 'Gauge', 'Object', 'Name', 'Needle Type']

def get_file_str(file_name):
    '''str -> str
    Takes the contents of the filename file_name and returns them as a single str'''
    
    return open(file_name, 'r').read()

def seperation_tests(file_str):
    '''str -> NoneType
    Print the results get_tags and get_chart on file_str'''
    print get_tags(file_str)
    print get_chart(file_str)
    
def tag_tests(file_str):
    '''str -> NoneType
    Print the results find_tag for every tag type give file_str'''
    for tag in TAGS:
        print find_tag(tag, file_str)
        
def chart_tests(file_str):
    '''str -> NoneType
    Print the results of create_chart for the file_str, which each list on its
    own line.'''
    
    for i in create_chart(file_str):
        print i

def check_sanity(file_str):
    print sanity_check(file_str)
    
def stitch_tests(file_str):
    chart = create_chart(file_str)
    for i in range(len(chart)):
        for j in range(len(chart[i])):
            print get_formatted_stitch(i+1, j+1, chart)
            
def run_tests(file_name):
    '''str -> NoneType
    Run tests on the given file_name. The file must be in the same directory
    as a1 and a1_test_script.'''

    file_str = get_file_str(file_name)
    print '****************Seperation tests****************'
    seperation_tests(file_str)
    
    print '****************Tag tests****************'
    tag_tests(file_str)

    print '****************Chart tests****************'
    chart_tests(file_str)
    
    print '****************Stitch Formatting tests****************'
    stitch_tests(file_str)
    
    print '****************Sanity tests****************'
    check_sanity(file_str)
    
    
if __name__ == '__main__':

    run_tests('acadian.knf')
    run_tests('BoardwalkA.knf')
    run_tests('Dragonfly_Chart.knf')
    