コード例 #1
0
def test_table_getters_and_setters():
    
    table = Table("example_name.dat")
    if table.get_type() != "data":
        print("Default Table type must be data.")

    try:
        table.get_attributes()
    except:
        a = 0 # This code does nothing, but is necessary for the except block
    else:
        print("get_attributes() must raise an exception when no attributes are set.")
    
    table.set_attributes(["col1", "col2", "col3"])
    if table.get_attributes() != ["col1", "col2", "col3"]:
        print("Attributes not set correctly.")
    
    table.set_key("col1")
    if table.get_key() != "col1":
        print("Key not set correctly.") 
    
    try:
        table.set_key("non_existant_attribute")
    except:
        a = 0 # This code does nothing, but is necessary for the except block
    else:
        print("set_key() must raise an exception when key is not an attribute.")
    
    table.set_type("configuration")
    if table.get_attributes() != ["table_name", "degree", "list_of_attributes"]:
        print("Attributes not set correctly for 'configuration' type.")
    
    try:
        table.set_attributes(["incorrect_col1", "incorrect_col2", "incorrect_col3"])
    except:
        a = 0 # This code does nothing, but is necessary for the except block
    else:
        print("set_attributes() must raise an exception when wrong attributes are set for 'configuration' type.")