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)
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)
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) 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
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
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)
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)
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