Exemplo n.º 1
0
def test_DataStore():
    """
    Test the data storage object.
    """
    from clair.xmlio import DataStore
    
    d = DataStore()
    
    info("Robust behavior when no data is present. - Must not crash")
    d.read_data(relative("."))
    
    info("")
    info("Must load real data")
    d.read_data(relative("../../example-data"))
    assert len(d.products) > 0
    assert len(d.tasks) > 0
    assert len(d.listings) > 0
    
    print "finished"
Exemplo n.º 2
0
def test_DataStore_write_expected_products_to_listings():
    """
    Test writing the "expected_product" fields of listings. 
    """
    print "Start"
    from clair.xmlio import DataStore
    
    #Read example data from disk
    data = DataStore()
    data.read_data(relative("../../example-data"))
    #remember existing data frame for later tests
    old_listings = data.listings.copy()

    #Find a test task
    test_task = data.tasks[1]
    test_task_id = test_task.id
    
    #Put new contents into task's "expected_products" field
    test_task.expected_products = ["foo", "bar", "baz"]
    
    print test_task_id
    print test_task
    print

    #The test:
    #The new expected product "foo" must be put into ``test task``, and into all
    #listings that are associated with ``test task``.
    data.write_expected_products_to_listings(test_task_id)
    
    #All listings that are associated with ``test_task`` must contain new 
    #listings ``["foo", "bar", "baz"]``
    n_prods = 0
    for _, listing in data.listings.iterrows():
        if test_task_id in listing["search_tasks"]:
#            print listing["id"], listing["expected_products"], listing["title"]
            assert listing["expected_products"] == test_task.expected_products
            n_prods += 1
    assert n_prods > 10
    
    #Compare old listings with current listings:
    #All data must be the same, except column "expected_products"
    del data.listings["expected_products"]
    del old_listings["expected_products"]
    #Indexes must be sorted for the comparison
    data.listings = data.listings.sort_index()
    old_listings = old_listings.sort_index()
    #The equality test itself
    assert_frames_equal(old_listings, data.listings)
    
    print "Finished"
Exemplo n.º 3
0
def test_DataStore_update_expected_products():
    """
    Test updating the "expected_product" fields of listings and tasks. 
    """
    from clair.xmlio import DataStore
    
    print "start"
    
    #Read example data from disk
    data = DataStore()
    data.read_data(relative("../../example-data"))
    
    #remember existing data frame for later tests
    old_listings = data.listings.copy()

    #Find a test task and test listing
    test_listing = data.listings.ix[0]
    test_task_id = test_listing["search_tasks"][0]
    test_task = None
    for test_task in data.tasks:
        if test_task.id == test_task_id:
            break
    #Put additional expected product into test listing
    data.listings["expected_products"][0] += ["foo"]
    
#    print test_listing[["title", "search_tasks", "expected_products"]]
#    print test_task_id
#    print test_task
#    print

    #The test:
    #The new expected product "foo" must be put into ``test task``, and into all
    #listings that are associated with ``test task``.
    data.update_expected_products(test_task_id)
    
    #The expected products field in the task must contain the new product "foo"
    print test_task
    assert "foo" in test_task.expected_products
    
    #All listings that are associated with test task must contain new listing foo
    new_exp_prods = test_task.expected_products
    n_prods = 0
    for _, listing in data.listings.iterrows():
        if test_task_id in listing["search_tasks"]:
#            print listing["id"], listing["expected_products"], listing["title"]
            assert "foo" in listing["expected_products"]
            assert listing["expected_products"] == new_exp_prods
            n_prods += 1
    assert n_prods > 10
    
    #Compare old listings with current listings:
    #All data must be the same, except column "expected_products"
    del data.listings["expected_products"]
    del old_listings["expected_products"]
    #Indexes must be sorted for the comparison
    data.listings = data.listings.sort_index()
    old_listings = old_listings.sort_index()
    #The equality test itself
    assert_frames_equal(old_listings, data.listings)
    
    print "finished"