Beispiel #1
0
def test_LearnDataProxyModel():
    """Test class RadioButtonModel"""
    from clair.qtgui import LearnDataProxyModel, ListingsModel
    from clair.coredata import make_listing_frame, DataStore
    csr =  Qt.CheckStateRole

    
    #Create test data
    listings = make_listing_frame(1)
    #Product "foo" is present, "bar" absent, nothing is known about "baz" 
    listings["expected_products"][0] = ["foo", "bar", "baz"]
    listings["products"][0]         = ["foo"]
    listings["products_absent"][0]   = ["bar"]
    data_store = DataStore()
    data_store.merge_listings(listings)
    #Create listings model that we can adapt
    lsmod = ListingsModel()
    lsmod.setDataStore(data_store)
    
    
    mo = LearnDataProxyModel()
    mo.setListingsModel(lsmod, 3, 4, 5)
    mo.setRow(lsmod.index(0, 0))
    
    print mo.values
    
    #Test size
    assert mo.columnCount() == 4
    assert mo.rowCount() == 4    #includes additional empty row
    
    #Test data conversion
    #1st row: [True, False, "foo", ...]
    assert bool(mo.data(mo.index(0, 0), csr)) == True
    assert bool(mo.data(mo.index(0, 1), csr)) == False
    assert mo.data(mo.index(0, 2)) == "foo"
    #2nd row: [False, True, "bar", ...]
    assert bool(mo.data(mo.index(1, 0), csr)) == False
    assert bool(mo.data(mo.index(1, 1), csr)) == True
    assert mo.data(mo.index(1, 2)) == "bar"
    #3rd row: [False, False, "baz", ...]
    assert bool(mo.data(mo.index(2, 0), csr)) == False
    assert bool(mo.data(mo.index(2, 1), csr)) == False
    assert mo.data(mo.index(2, 2)) == "baz"
    
    #Change the data
    mo.setData(mo.index(0, 0), False, csr)
    mo.setData(mo.index(1, 0), True, csr)
    mo.setData(mo.index(2, 1), True, csr)
    
    #Test conversion back to internal format
    assert data_store.listings["expected_products"][0] == ["foo", "bar", "baz"]
    assert data_store.listings["products"][0]          == ["bar"]
    assert data_store.listings["products_absent"][0]   == ["baz"]
    
    print "finished successfully."
Beispiel #2
0
def test_LearnDataProxyModel_GUI():
    """Test class RadioButtonModel"""
    from clair.qtgui import LearnDataProxyModel, ListingsModel
    from clair.coredata import make_listing_frame, DataStore
    
    print "Start"
    app = QApplication(sys.argv)
    
    #Create test data
    listings = make_listing_frame(1)
    #Product "foo" is present, "bar" absent, nothing is known about "baz" 
    listings["expected_products"][0] = ["foo", "bar", "baz"]
    listings["products"][0]         = ["foo"]
    listings["products_absent"][0]   = ["bar"]
    data_store = DataStore()
    data_store.merge_listings(listings)
    #Create listings model that we can adapt
    lsmod = ListingsModel()
    lsmod.setDataStore(data_store)
    
    mo = LearnDataProxyModel()
    mo.setListingsModel(lsmod, 3, 4, 5)
    mo.setRow(lsmod.index(0, 0))

    view = QTreeView()
    view.setModel(mo)
    
    view.show()
    app.exec_()
    
    print mo.values
    print "expectedProducts:", data_store.listings["expected_products"][0]
    print "products:        ", data_store.listings["products"][0]
    print "productsAbsent:  ", data_store.listings["products_absent"][0]
    
    print "End"