def test_basic_functionality(driver, test_file):
    try:
        #Test page response by clicking the reset button and applying new code to ace-editor

        tt.reset_page(driver)
        tt.update_editor(driver, test_file)
        ens_elements = driver.find_elements_by_xpath('//*[@class="ens"]')
        assert (len(ens_elements) > 0)
        side_script = '''var right = document.getElementById("rightpane"); \
		right.style.width = "200px"
		'''
        driver.execute_script(side_script)

        #Creates graph objects by right clicking on nodes and selecting from menu
        actions = ActionChains(driver)
        elements = ['node', 'ens']
        for elem in elements:
            node = driver.find_element_by_xpath('//*[@class="' + elem + '"]')
            actions = ActionChains(driver)
            actions.move_to_element(node)
            actions.context_click()
            actions.perform()
            time.sleep(1)
            actions = ActionChains(driver)

            menu = driver.find_element_by_xpath(
                '//*[@class="dropdown-menu"]/li[1]')
            actions.move_to_element(menu)
            actions.click()
            actions.perform()
            time.sleep(0.5)

        graph_elements = driver.find_elements_by_xpath('//*[@class="graph"]')

        assert len(graph_elements) > 0
        tt.start_stop_sim(driver)
        time.sleep(1.5)
        tt.start_stop_sim(driver)
        time.sleep(0.5)

        ticker = driver.find_element_by_xpath('//*[@id="ticks_tr"]/td')
        sim_time = ticker.get_attribute('textContent')

        assert (float(sim_time) > 0)

    except Exception as e:
        #Travis Only: On fail takes screenshot and uploads it to imgur

        if ('TRAVIS' in os.environ):
            tt.imgur_screenshot(driver)

        _, _, tb = sys.exc_info()
        traceback.print_tb(tb)  # Fixed format
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]

        print('An error occurred on line {} in statement {}'.format(
            line, text))
        print(str(e))
        exit(1)
Esempio n. 2
0
def test_config_persists(driver):
    tt.reset_page(driver)
    menu = driver.find_element_by_id('Config_menu')
    actions = ActionChains(driver)
    actions.move_to_element(menu)
    actions.click()
    actions.perform()
    time.sleep(0.5)
    button = driver.find_element_by_id("Config_button")
    actions = ActionChains(driver)
    actions.move_to_element(button)
    actions.click()
    actions.perform()
    time.sleep(1.0)

    actions = ActionChains(driver)
    checkbox = driver.find_element_by_id("zoom-fonts")
    actions.move_to_element(checkbox)
    actions.click()
    actions.perform()
    time.sleep(0.5)

    val = driver.execute_script("return localStorage.getItem('ng.zoom_fonts')")
    assert val == 'true'

    actions.perform()  # do it again to go back to default (False)
    val = driver.execute_script("return localStorage.getItem('ng.zoom_fonts')")
    assert val == 'false'
Esempio n. 3
0
def test_save_as(driver):
    # Saves the default.py file as test_download, tests whether it downloaded
    # correctly.
    tt.reset_page(driver)
    download_file(driver,"nengo_gui/examples/test_download.py")


    # Finds files to be read
    project_root = os.path.dirname(inspect.getfile(nengo_gui))
    test_file = os.path.join(project_root,"examples/test_download.py")
    test_file_conf = os.path.join(project_root,"examples/test_download.py.cfg")
    default_file = os.path.join(project_root,"examples/default.py")

    assert(os.path.isfile(test_file))
    with open(test_file,'r') as f1:
        test_code = f1.read()
    with open(default_file,'r') as f2:
        default_code = f2.read()

    assert test_code == default_code

    # Deletes downloaded files
    os.remove(test_file)
    os.remove(test_file_conf)

    download_file(driver,"nengo_gui/examples/default.py")
    time.sleep(2)
    try:
        alert = driver.switch_to_alert()
        alert.accept()
    except:
        print("No warning present")
        assert(False)
Esempio n. 4
0
def test_save_as(driver):
    # Saves the default.py file as test_download, tests whether it downloaded
    # correctly.
    tt.reset_page(driver)
    download_file(driver, "nengo_gui/examples/test_download.py")

    # Finds files to be read
    project_root = os.path.dirname(nengo_gui.__file__)
    test_file = os.path.join(project_root, "examples", "test_download.py")
    test_file_conf = os.path.join(project_root, "examples",
                                  "test_download.py.cfg")
    default_file = os.path.join(project_root, "examples", "default.py")

    assert (os.path.isfile(test_file))
    with open(test_file, 'r') as f1:
        test_code = f1.read()
    with open(default_file, 'r') as f2:
        default_code = f2.read()

    assert test_code == default_code

    # Deletes downloaded files
    os.remove(test_file)
    os.remove(test_file_conf)

    download_file(driver, "nengo_gui/examples/default.py")
    time.sleep(2)
    try:
        alert = driver.switch_to_alert()
        alert.accept()
    except:
        assert False, "No warning present"
Esempio n. 5
0
def test_tutorial_basic(driver, test_file):
	# Tests the first 18 tutorials, these are the tutorials that do not
	# utilize networks or SPA which require a different format of test

	try:
		#Test page response by clicking the reset button and applying new code to ace-editor

		tt.reset_page(driver)
		tt.update_editor(driver, test_file)

		side_script = '''var right = document.getElementById("rightpane"); \
		right.style.width = "200px"
		'''
		driver.execute_script(side_script)

		node_objects = driver.find_elements_by_xpath('//*[@class="node"]')
		ens_objects = driver.find_elements_by_xpath('//*[@class="ens"]')

		node_number = test_file.count("nengo.Node")
		ens_number = test_file.count("nengo.Ensemble")

		# Makes sure the correct number of ensembles and nodes were rendered
		assert(len(node_objects)/2 == node_number)
		assert(len(ens_objects)/2 == ens_number)

		# Tests whether the file compiles and runs

		hang_time = 25 # alloted time until test fails


		compiled = False
		tt.start_stop_sim(driver)
		time_start = time.time()
		while(time.time() - time_start < hang_time):
			time_script = 'var time = $("#ticks_tr"); \
			return time.find("td").text()'
			sim_time = driver.execute_script(time_script)
			if(float(sim_time) > 0):
				compiled = True
				break
			time.sleep(0.1)

		assert(compiled)

	except Exception, e:
		#Travis Only: On fail takes screenshot and uploads it to imgur


		if('TRAVIS' in os.environ):
			tt.imgur_screenshot(driver)

		_, _, tb = sys.exc_info()
		traceback.print_tb(tb) # Fixed format
		tb_info = traceback.extract_tb(tb)
		filename, line, func, text = tb_info[-1]

		print('An error occurred on line {} in statement {}'.format(line, text))
		print(str(e))
		exit(1)
def test_tutorial_basic(driver, test_file):
    # Tests the first 18 tutorials, these are the tutorials that do not
    # utilize networks or SPA which require a different format of test

    try:
        #Test page response by clicking the reset button and applying new code to ace-editor

        tt.reset_page(driver)
        tt.update_editor(driver, test_file)

        side_script = '''var right = document.getElementById("rightpane"); \
		right.style.width = "200px"
		'''
        driver.execute_script(side_script)

        node_objects = driver.find_elements_by_xpath('//*[@class="node"]')
        ens_objects = driver.find_elements_by_xpath('//*[@class="ens"]')

        node_number = test_file.count("nengo.Node")
        ens_number = test_file.count("nengo.Ensemble")

        # Makes sure the correct number of ensembles and nodes were rendered
        assert (len(node_objects) / 2 == node_number)
        assert (len(ens_objects) / 2 == ens_number)

        # Tests whether the file compiles and runs

        hang_time = 25  # alloted time until test fails

        compiled = False
        tt.start_stop_sim(driver)
        time_start = time.time()
        while (time.time() - time_start < hang_time):
            time_script = 'var time = $("#ticks_tr"); \
			return time.find("td").text()'

            sim_time = driver.execute_script(time_script)
            if (float(sim_time) > 0):
                compiled = True
                break
            time.sleep(0.1)

        assert (compiled)

    except Exception, e:
        #Travis Only: On fail takes screenshot and uploads it to imgur

        if ('TRAVIS' in os.environ):
            tt.imgur_screenshot(driver)

        _, _, tb = sys.exc_info()
        traceback.print_tb(tb)  # Fixed format
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]

        print('An error occurred on line {} in statement {}'.format(
            line, text))
        print(str(e))
        exit(1)
def test_basic_functionality(driver, test_file):
	try:
		#Test page response by clicking the reset button and applying new code to ace-editor

		tt.reset_page(driver)
		tt.update_editor(driver, test_file)
		ens_elements = driver.find_elements_by_xpath('//*[@class="ens"]')
		assert (len(ens_elements) > 0)
		side_script = '''var right = document.getElementById("rightpane"); \
		right.style.width = "200px"
		'''
		driver.execute_script(side_script)

		#Creates graph objects by right clicking on nodes and selecting from menu
		actions = ActionChains(driver)
		elements = ['node', 'ens']
		for elem in elements:
			node = driver.find_element_by_xpath('//*[@class="'+elem+'"]')
			actions = ActionChains(driver)
			actions.move_to_element(node)
			actions.context_click()
			actions.perform()
			time.sleep(1)
			actions = ActionChains(driver)

			menu = driver.find_element_by_xpath('//*[@class="dropdown-menu"]/li[1]')
			actions.move_to_element(menu)
			actions.click()
			actions.perform()
			time.sleep(0.5)

		graph_elements = driver.find_elements_by_xpath('//*[@class="graph"]')

		assert len(graph_elements) > 0
		tt.start_stop_sim(driver)
		time.sleep(1.5)
		tt.start_stop_sim(driver)
		time.sleep(0.5)

		ticker = driver.find_element_by_xpath('//*[@id="ticks_tr"]/td')
		sim_time = ticker.get_attribute('textContent')

		assert (float(sim_time) > 0)

	except Exception as e:
		#Travis Only: On fail takes screenshot and uploads it to imgur


		if('TRAVIS' in os.environ):
			tt.imgur_screenshot(driver)

		_, _, tb = sys.exc_info()
		traceback.print_tb(tb) # Fixed format
		tb_info = traceback.extract_tb(tb)
		filename, line, func, text = tb_info[-1]

		print('An error occurred on line {} in statement {}'.format(line, text))
		print(str(e))
		exit(1)
Esempio n. 8
0
def test_example(driver):
    # Always include driver as a function parameter.
    # This is the selenium webdriver that will allow
    # you to interact with the webpage.

    tt.reset_page(driver)
    # Most testing_tools functions require driver as an input.
    # Presses the reset button to start the page fresh.
    # Usually useful but not always needed.
    # More documentation on testing_tools can be found
    # in nengo_gui/testing_tools.py

    time.sleep(1)
    # Waits a small amount of time to ensure the page has
    # time to reset.

    tt.update_editor(
        driver, '''
import nengo

model = nengo.Network()
with model:
    stim = nengo.Node([0])
    a = nengo.Ensemble(n_neurons=50, dimensions=1)
    nengo.Connection(stim, a)
		''')
    # The page will now load this code into the code editor

    stim = driver.find_element_by_xpath('//*[@class="node"]')
    a = driver.find_element_by_xpath('//*[@class="ens"]')
    # Finds the 'stim' and 'a' nodes and saves them as a webElements.

    action = ActionChains(driver)
    # ActionChains allow you to link together multiple mouse events
    # then execute them in that order.

    action.move_to_element(stim)
    action.context_click()
    action.perform()
    time.sleep(1)
    # The stim element has now been right clicked.

    # WARNING: when using ActionChains reinitialize ActionChains
    # after every .perform() call, it is not clear why but
    # ActionChains does not seem to reset properly after this call.

    right_click_menu = driver.find_element_by_xpath(
        '//*[@class="dropdown-menu"]')

    assert (bool(stim) and bool(a) == True)
    # Tests if both elements are present.

    assert (bool(right_click_menu) == True)
    # Tests if stim has been properly clicked

    if ('TRAVIS' in os.environ):  ########## TRAVIS ONLY
        tt.imgur_screenshot(driver)
Esempio n. 9
0
def test_data_to_csv(driver):
    tt.reset_page(driver)

    tt.update_editor(driver, """
import nengo
model = nengo.Network()
with model:
    stim = nengo.Node([0])
    a = nengo.Ensemble(n_neurons=50, dimensions=1)
    nengo.Connection(stim, a)
    """)

    time.sleep(1)

    actions = ActionChains(driver)
    elements = ['node', 'ens']
    for elem in elements:
        for x in range(2):
            node = driver.find_element_by_xpath('//*[@class="'+elem+'"]')

            actions = ActionChains(driver)
            actions.move_to_element(node)
            actions.context_click()
            actions.perform()
            time.sleep(1)
            actions = ActionChains(driver)

            menu = driver.find_element_by_xpath(
                '//*[@class="dropdown-menu"]/li[%d]' % (x+1))
            actions.move_to_element(menu)
            actions.click()
            actions.perform()

            time.sleep(0.5)
    driver.execute_script("""
a = function() {
    var data_set = Nengo.Component.components;
    data_set.forEach(function(data, index) {
        if (data.constructor === Nengo.Value) {
            data.data_store.reset();
            data.data_store.push([1, 10+index]);
        }
    });
    return data_to_csv(data_set);
};
    """)

    time.sleep(1)

    result = driver.execute_script("return a();")
    test_data = ("Graph Name,stim,a\n"
                 "Times,Dimension1,Dimension1\n"
                 "1,11,12")

    assert result == test_data
Esempio n. 10
0
def test_example(driver):
	# Always include driver as a function parameter.
	# This is the selenium webdriver that will allow
	# you to interact with the webpage.

	tt.reset_page(driver)
	# Most testing_tools functions require driver as an input.
	# Presses the reset button to start the page fresh.
	# Usually useful but not always needed.
	# More documentation on testing_tools can be found
	# in nengo_gui/testing_tools.py

	time.sleep(1)
	# Waits a small amount of time to ensure the page has
	# time to reset.

	tt.update_editor(driver,'''
import nengo

model = nengo.Network()
with model:
    stim = nengo.Node([0])
    a = nengo.Ensemble(n_neurons=50, dimensions=1)
    nengo.Connection(stim, a)
		''')
	# The page will now load this code into the code editor

	stim = driver.find_element_by_xpath('//*[@class="node"]')
	a = driver.find_element_by_xpath('//*[@class="ens"]')
	# Finds the 'stim' and 'a' nodes and saves them as a webElements.

	action = ActionChains(driver)
	# ActionChains allow you to link together multiple mouse events
	# then execute them in that order.

	action.move_to_element(stim);
	action.context_click()
	action.perform()
	time.sleep(1)
	# The stim element has now been right clicked.

	# WARNING: when using ActionChains reinitialize ActionChains
	# after every .perform() call, it is not clear why but
	# ActionChains does not seem to reset properly after this call.

	right_click_menu = driver.find_element_by_xpath('//*[@class="dropdown-menu"]')

	assert(bool(stim) and bool(a) == True)
	# Tests if both elements are present.

	assert(bool(right_click_menu) == True)
	# Tests if stim has been properly clicked

	if('TRAVIS' in os.environ): ########## TRAVIS ONLY
		tt.imgur_screenshot(driver)
def test_basic_functionality(driver, test_file):
    try:
        # Test page response by clicking the reset button and applying
        # new code to ace-editor
        tt.reset_page(driver)
        time.sleep(0.5)
        tt.update_editor(driver, test_file)
        tt.mouse_scroll(driver, 500)
        ens_elements = driver.find_elements_by_xpath('//*[@class="ens"]')
        assert (len(ens_elements) > 0)
        side_script = ("var right = document.getElementById('rightpane');\n"
                       "right.style.width = '200px';\n")
        driver.execute_script(side_script)

        # Creates graph objects by right clicking and selecting
        actions = ActionChains(driver)
        elements = ['node', 'ens']
        for elem in elements:
            node = driver.find_element_by_xpath('//*[@class="' + elem + '"]')
            actions = ActionChains(driver)
            actions.move_to_element(node)
            actions.context_click()
            actions.perform()
            time.sleep(1)
            actions = ActionChains(driver)

            menu = driver.find_element_by_xpath(
                '//*[@class="dropdown-menu"]/li[1]')
            actions.move_to_element(menu)
            actions.click()
            actions.perform()
            time.sleep(0.5)

        graph_elements = driver.find_elements_by_xpath('//*[@class="graph"]')

        assert len(graph_elements) > 0
        tt.start_stop_sim(driver)
        time.sleep(1.5)
        tt.start_stop_sim(driver)
        time.sleep(0.5)

        ticker = driver.find_element_by_xpath('//*[@id="ticks_tr"]/td')
        sim_time = ticker.get_attribute('textContent')

        assert (float(sim_time) > 0)

    except:
        # Travis Only: On fail takes screenshot and uploads it to imgur
        if ('TRAVIS' in os.environ):
            tt.imgur_screenshot(driver)
        raise
Esempio n. 12
0
def test_data_to_csv(driver):
	tt.reset_page(driver)

	tt.update_editor(driver,'''
import nengo
model = nengo.Network()
with model:
    stim = nengo.Node([0])
    a = nengo.Ensemble(n_neurons=50, dimensions=1)
    nengo.Connection(stim, a)
		''')

	time.sleep(1)

	actions = ActionChains(driver)
	elements = ['node','ens']
	for elem in elements:
		for x in range(2):
			node = driver.find_element_by_xpath('//*[@class="'+elem+'"]')

			actions = ActionChains(driver)
			actions.move_to_element(node)
			actions.context_click()
			actions.perform()
			time.sleep(1)
			actions = ActionChains(driver)

			menu = driver.find_element_by_xpath('//*[@class="dropdown-menu"]/li['+str(x+1)+']')
			actions.move_to_element(menu)
			actions.click()
			actions.perform()

			time.sleep(0.5)
	driver.execute_script("""a = function(){var data_set = Nengo.Component.components
data_set.forEach(function(data,index){
if(data.constructor === Nengo.Value){
   data.data_store.reset();
   data.data_store.push([1,10+index]);
};
}); return data_to_csv(data_set)};""")

	time.sleep(1)

	result = driver.execute_script("return a()")
	print result
	test_data = '''Graph Name,stim,a
Times,Dimension1,Dimension1
1,11,12'''

	assert result == test_data
Esempio n. 13
0
def test_tutorial_basic(driver, test_file):
    # Tests the first 18 tutorials. These are the tutorials that do not
    # utilize networks or SPA which require a different format of test

    try:
        # Test page response by clicking the reset button and applying
        # new code to ace-editor
        tt.reset_page(driver)
        time.sleep(1)
        tt.update_editor(driver, test_file)
        tt.mouse_scroll(driver, 500)
        time.sleep(2)
        side_script = ("var right = document.getElementById('rightpane');\n"
                       "right.style.width = '200px';\n")
        driver.execute_script(side_script)

        node_objects = driver.find_elements_by_xpath('//*[@class="node"]')
        ens_objects = driver.find_elements_by_xpath('//*[@class="ens"]')

        node_number = test_file.count("nengo.Node")
        ens_number = test_file.count("nengo.Ensemble")

        # Makes sure the correct number of ensembles and nodes were rendered
        assert (len(node_objects) / 2 == node_number)
        assert (len(ens_objects) / 2 == ens_number)

        # Tests whether the file compiles and runs
        hang_time = 25  # alloted time until test fails

        time_script = ("var time = $('#ticks_tr');\n"
                       "return time.find('td').text()\n")
        tt.start_stop_sim(driver)
        time_start = time.time()
        while time.time() - time_start < hang_time:
            sim_time = driver.execute_script(time_script)
            if float(sim_time) > 0:
                break
            time.sleep(0.1)
        else:
            assert False, "Did not compile in %f seconds" % hang_time

    except:
        # Travis Only: On fail takes screenshot and uploads it to imgur
        if ('TRAVIS' in os.environ):
            tt.imgur_screenshot(driver)
        raise
Esempio n. 14
0
def test_config_persists(driver):
    tt.reset_page(driver)
    actions = ActionChains(driver)
    button = driver.find_element_by_id("Config_button")
    actions.move_to_element(button)
    actions.click()
    actions.perform()
    time.sleep(1.0)

    actions = ActionChains(driver)
    checkbox = driver.find_element_by_id("zoom-fonts")
    actions.move_to_element(checkbox)
    actions.click()
    actions.perform()
    time.sleep(0.5)

    val = driver.execute_script("return localStorage.getItem('ng.zoom_fonts')")
    assert val == 'true'

    actions.perform()  # do it again to go back to default (False)
    val = driver.execute_script("return localStorage.getItem('ng.zoom_fonts')")
    assert val == 'false'
Esempio n. 15
0
def test_pdb_error(driver):
	test_file = '''
import nengo
import pdb

model = nengo.Network()
with model:
    pdb.set_trace()
    stim = nengo.Node([0])
    a = nengo.Ensemble(n_neurons=50, dimensions=1)
    nengo.Connection(stim, a)
	'''
	tt.reset_page(driver)
	tt.update_editor(driver,test_file)
	time.sleep(0.5)
	tt.start_stop_sim(driver)
	time.sleep(1.5)
	tt.start_stop_sim(driver)
	time.sleep(0.5)

	ticker = driver.find_element_by_xpath('//*[@id="ticks_tr"]/td')
	sim_time = ticker.get_attribute('textContent')

	assert (float(sim_time) > 0)
Esempio n. 16
0
def test_spa(driver):
    # Tests the functionality of SPA simulations

    try:
        #Test page response by clicking the reset button and applying new code to ace-editor
        test_file  = """
import nengo
import nengo.spa as spa

D = 2  # the dimensionality of the vectors

model = spa.SPA()
with model:
    model.color = spa.State(D)
    model.shape = spa.State(D)
    model.memory = spa.State(D, feedback=1)
    model.query = spa.State(D)
    model.answer = spa.State(D)

    actions = spa.Actions(
        "memory = color * shape",
        "answer = memory * ~query",
        )

    model.cortical = spa.Cortical(actions)
        """
        tt.reset_page(driver)
        tt.update_editor(driver, test_file)
        tt.mouse_scroll(driver,200)

        # Generates semantic pointer clouds for each network
        driver.execute_script("""
        var a = Nengo.netgraph.svg_objects;
        for(model in a){
            if(a[model].sp_targets.length > 0){
                a[model].create_graph('Pointer',a[model].sp_targets[0]);
                a[model].create_graph('SpaSimilarity',a[model].sp_targets[0]);
            }
        };
        """)
        time.sleep(1)
        # Ensures the simulation has started
        hang_time = 100 # alloted time until test fails
        compiled = False
        tt.start_stop_sim(driver)
        time_start = time.time()
        while(time.time() - time_start < hang_time):
        	time_script = 'var time = $("#ticks_tr"); \
        	return time.find("td").text()'
        	sim_time = driver.execute_script(time_script)
        	if(float(sim_time) > 0):
        		compiled = True
        		break
        	time.sleep(1)

        assert(compiled)

        # Sets the semantic pointers appropriately
        spa_values = {"shape":"CIRCLE", "color":"BLUE", "query":"CIRCLE"}
        set_cloud_value(driver,spa_values)
        time.sleep(10)
        result = driver.execute_script("""
        var objects = Nengo.Component.components;
        var answer = objects.filter(function(item){
              return item.label.innerHTML == "answer";}
        )[0];
        var answer_data = answer.data_store.data[0];
        var result = answer_data.pop();
        return result
        """)

        data_script = """
        shape_data = Nengo.Component.components.filter(function(item){
            return (item.constructor === Nengo.SpaSimilarity);
        })[0].data_store.data;
        return shape_data;
        """
        plot_data = driver.execute_script(data_script)

        # Checks that the 'answer' is BLUE
        assert(len(filter((lambda x: ("BLUE" in x)),result)) > 0)

        # Checks the dimensionality of the spa similarity plot
        assert(len(plot_data) == 2 and len(plot_data[0]) > 1)

        set_cloud_value(driver,{"color":"ORANGE"})

        time.sleep(5)

        plot_data = driver.execute_script(data_script)

        # Checks that the data store grows when input changes
        assert(len(plot_data) == 3 and len(plot_data[0]) > 1)

    except Exception as e:
        #Travis Only: On fail takes screenshot and uploads it to imgur


        if('TRAVIS' in os.environ):
        	tt.imgur_screenshot(driver)

        _, _, tb = sys.exc_info()
        traceback.print_tb(tb) # Fixed format
        tb_info = traceback.extract_tb(tb)
        filename, line, func, text = tb_info[-1]

        print('An error occurred on line {} in statement {}'.format(line, text))
        print(str(e))
        exit(1)
Esempio n. 17
0
def test_spa(driver):
    """Tests the functionality of SPA simulations"""

    try:
        test_file = """
import nengo
import nengo.spa as spa

D = 2  # the dimensionality of the vectors

model = spa.SPA()
with model:
    model.color = spa.State(D)
    model.shape = spa.State(D)
    model.memory = spa.State(D, feedback=1)
    model.query = spa.State(D)
    model.answer = spa.State(D)

    actions = spa.Actions(
        "memory = color * shape",
        "answer = memory * ~query",
        )

    model.cortical = spa.Cortical(actions)
"""
        tt.reset_page(driver)
        time.sleep(0.2)
        tt.update_editor(driver, test_file)
        tt.mouse_scroll(driver, 200)

        # Generates semantic pointer clouds for each network
        driver.execute_script("""
var a = Nengo.netgraph.svg_objects;
for (model in a) {
    if (a[model].sp_targets.length > 0) {
        a[model].create_graph('Pointer', a[model].sp_targets[0]);
        a[model].create_graph('SpaSimilarity', a[model].sp_targets[0]);
    }
}
""")
        time.sleep(1)
        # Ensures the simulation has started

        hang_time = 100  # alloted time until test fails
        time_script = ("var time = $('#ticks_tr');\n"
                       "return time.find('td').text();\n")
        tt.start_stop_sim(driver)
        time_start = time.time()
        while time.time() - time_start < hang_time:
            sim_time = driver.execute_script(time_script)
            if (float(sim_time) > 0):
                break
            time.sleep(1)
        else:
            assert False, "Did not compile in %f seconds" % hang_time

        # Sets the semantic pointers appropriately
        spa_values = {"shape": "CIRCLE", "color": "BLUE", "query": "CIRCLE"}
        set_cloud_value(driver, spa_values)
        time.sleep(10)
        result = driver.execute_script("""
var objects = Nengo.Component.components;
var answer = objects.filter(function(item) {
    return item.label.innerHTML == "answer";
})[0];
var answer_data = answer.data_store.data[0];
var result = answer_data.pop();
return result;
""")

        data_script = """
return Nengo.Component.components.filter(function(item) {
    return (item.constructor === Nengo.SpaSimilarity);
})[0].data_store.data;
"""
        plot_data = driver.execute_script(data_script)

        # Checks that the 'answer' is BLUE
        assert any("BLUE" in x for x in result)

        # Checks the dimensionality of the spa similarity plot
        assert len(plot_data) == 2 and len(plot_data[0]) > 1

        set_cloud_value(driver, {"color": "ORANGE"})

        time.sleep(10)

        plot_data = driver.execute_script(data_script)

        # Checks that the data store grows when input changes
        assert (len(plot_data) == 3 and len(plot_data[0]) > 1)

    except:
        # Travis Only: On fail takes screenshot and uploads it to imgur
        if ('TRAVIS' in os.environ):
            tt.imgur_screenshot(driver)
        raise