示例#1
0
def set_type_attributes_correct():
    table = Table("table.txt")
    score = 0
    try:
        table.set_type("configuration")
        if table.get_attributes() == CONFIGURATION_ATTRIBUTES and table.get_degree() == 3 and table.get_key() == CONFIGURATION_KEY:
            score+=1
    except:
        a = 0
    table = Table("table.txt")
    try:
        table.set_type("inverted_index")
        if table.get_attributes() == INVERTED_INDEX_ATTRIBUTES and table.get_degree() == 2 and table.get_key() == INVERTED_INDEX_KEY:
            score+=1        
    except:
        a = 0
    return str(score)  
示例#2
0
def set_attributes_correct():
    table = Table("table.txt")
    try:
        table.set_attributes(["name", "age", "weight"])
        if table.get_attributes() == ["name", "age", "weight"] and table.get_degree() == 3 and table.get_key() == "name":
            return "2"
    except:
        return "0"
    return "0"
示例#3
0
def getters_raise_exceptions():
    table = Table("table.txt")
    try:
        table.get_degree()
        return "0"
    except:
        a = 0
    try:
        table.get_attributes()
        return "0"
    except:
        a = 0
    try:
        table.get_key()
        return "0"
    except:
        a = 0
    return "1"
示例#4
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.")