def test_to_json():
    try:
        print("\n*********** Testing to JSON. *******************\n")
        cat = CSVCatalog.CSVCatalog()
        cat.drop_table("teams")

        cds = []
        cds.append(CSVCatalog.ColumnDefinition('teamID', 'text', True))
        cds.append(CSVCatalog.ColumnDefinition('yearID', 'text', True))
        cds.append(CSVCatalog.ColumnDefinition('W', column_type='number'))

        tbl = CSVCatalog.TableDefinition(
            "teams", "data/Teams.csv", column_definitions=cds,
            cnx=cat.cnx)  # maybe this is inproper?
        r = json.dumps(tbl.to_json(), indent=2)
        print("Teams definition = \n", r)
        with open("unit_tests_catalog_json.txt", "w") as result_file:
            result_file.write(r)

        print("\n\n")
    except Exception as e:
        print(
            "My implementation throws a custom exception. You can print any meaningful error you want."
        )
        print("Could not create table. Exception = ", e)
        print("\n*********** Testing to JSON. *******************\n")
def test_table_def_to_json():
    print("\n*********** Testing table def to JSON. *******************\n")
    cds = list()
    cds.append(CSVCatalog.ColumnDefinition('teamID', 'text', True))
    cds.append(CSVCatalog.ColumnDefinition('yearID', 'text', True))
    cds.append(CSVCatalog.ColumnDefinition('AB', 'number'))

    tbl = CSVCatalog.TableDefinition(
        "batting",
        "../data/Batting.csv",
        column_definitions=cds)
    print(tbl.to_json())
def test2():
    a = CSVCatalog.TableDefinition()
    a.define_primary_key(['playerID', 'teamID', 'yearID', 'HR'])
    a.define_index("team_year_idx", ['teamID', 'yearID'], "INDEX")
def test1():
    a = CSVCatalog.TableDefinition()
    a.define_primary_key(['playerID', 'teamID', 'yearID', 'HR'])