def run_test(input_data): running_time = time.time() # Demux to the correct function try: if input_data["function"] == "pair": result = lab.acted_together(small_data, input_data["actor_1"], input_data["actor_2"]) # Actors with a given bacon number elif input_data["function"] == "set": result = lab.actors_with_bacon_number(small_data, input_data["n"]) # Paths in a small database elif input_data["function"] == "path_small": result = lab.get_bacon_path(small_data, input_data["actor_id"]) # Paths in a large database elif input_data["function"] == "path": result = lab.bacon_path(large_data, input_data["actor_id"]) running_time = time.time() - running_time return (running_time, result) except Exception: return ('error', traceback.format_exc())
def _run_pickled_together_test(n): filename = os.path.join( TEST_DIRECTORY, 'resources', 'tests', 'acted_together_%02d.pickle' % n, ) with open(filename, 'rb') as f: tests = pickle.load(f) for a1, a2, v in tests: res = lab.acted_together(db_large, a1, a2) assert res == v, f"expected {bool(v)} for {a1} and {a2} acting together, got {bool(res)}"
def test_01(self): # Simple test, two actors who acted together actor1 = 4724 actor2 = 9210 self.assertTrue(lab.acted_together(self.data, actor1, actor2))
def test_a(self): randInt = random.randint(0, len(self.data) - 1) actor_1 = self.data[randInt][0] actor_2 = self.data[randInt][1] self.assertTrue(lab.acted_together(self.data, actor_1, actor_2))
def test_acted_together(self): # Kristen Bone and Eduardo Yanez acted together or not actor1 = 141460 actor2 = 9211 self.assertFalse(lab.acted_together(self.data, actor1, actor2))
def test_04(self): # Toi Svane Stepp and Denise Richards acted together or not actor1 = 945237 actor2 = 9205 self.assertTrue(lab.acted_together(self.data, actor1, actor2)) print(lab.acted_together(self.data, actor1, actor2))
def test_acted_together_custom_02(): # Noam Jenkins and Neve Campbell actor1 = 33668 actor2 = 9206 assert lab.acted_together(db_small, actor1, actor2)
def test_acted_together_custom_01(): # Lindsey McKeon and Evan Glenn actor1 = 141495 actor2 = 1059003 assert not lab.acted_together(db_small, actor1, actor2)
def test_tiny_acted_together_04(): # Two actors who did not act together but are adjacent to each other actor1 = 2876 actor2 = 1640 assert lab.acted_together(db_tiny, actor1, actor2)
def test_acted_together_02(): # Simple test, two actors who had not acted together actor1 = 4724 actor2 = 16935 assert not lab.acted_together(db_small, actor1, actor2)
def test_acted_together_01(): # Simple test, two actors who acted together actor1 = 4724 actor2 = 9210 assert lab.acted_together(db_small, actor1, actor2)
def cat(params): path = os.path.join(cur_dir, params.get('path')) with open(path, 'r') as f: return f.read() def load_pickle(params): path = os.path.join(cur_dir, params.get('path')) with open(path, 'rb') as f: return pickle.load(f) special_routes = { '/ls': ls, '/cat': cat, '/load_pickle': load_pickle, '/better_together': lambda d: lab.acted_together(small_data, d['actor_1'], d['actor_2']), '/bacon_number': lambda d: list(lab.actors_with_bacon_number(small_data, d['n'])), '/bacon_path': lambda d: lab.bacon_path(small_data, d['actor_name']), '/restart': lambda d: (importlib.reload(lab) and {'ok': True}) } def application(environ, start_response): path = environ.get('PATH_INFO', '/') or '/' params = parse_post(environ) print(f'requested {path}, params: {params}') if path in special_routes: type_ = 'application/json' status = '200 OK' body = json.dumps(special_routes[path](params)).encode('utf-8')
def test_01(self): self.assertFalse(lab.acted_together(self.data, 4742, 4025))
def better_together(d): return lab.acted_together(small_data, d["actor_1"], d["actor_2"])
def test_02(self): # Simple test, two actors who had not acted together actor1 = 4724 actor2 = 16935 self.assertFalse(lab.acted_together(self.data, actor1, actor2))
def test_acted_together_03(): # Simple test, same actor actor1 = 4724 actor2 = 4724 assert lab.acted_together(db_small, actor1, actor2)
def test_03(self): # Simple test, same actor actor1 = 4724 actor2 = 4724 self.assertTrue(lab.acted_together(self.data, actor1, actor2))
def test_tiny_acted_together(): # Simple test, same actor actor1 = 2876 actor2 = 1532 assert lab.acted_together(db_tiny, actor1, actor2)