Ejemplo n.º 1
0
def test_bacon_path_05():
    # Bacon path, large database, length of 6 (7 actors, 6 movies)
    actor_id = 1345462
    len_expected = 6
    result = lab.bacon_path(db_large, actor_id)
    # here, we compute the result twice, to test for mutation of the db
    result = lab.bacon_path(db_large, actor_id)
    len_result = -1 if result is None else len(result) - 1

    check_valid_path(raw_db_large, result, 4724, actor_id, len_expected)
Ejemplo n.º 2
0
def test_bacon_path_02():
    # Bacon path, small database, length of 3 (4 actors, 3 movies)
    actor_id = 46866
    len_expected = 3

    first_result = lab.bacon_path(db_small, actor_id)
    second_result = lab.bacon_path(db_small, actor_id)

    check_valid_path(raw_db_small, first_result, 4724, actor_id, len_expected)
    check_valid_path(raw_db_small, second_result, 4724, actor_id, len_expected)
Ejemplo n.º 3
0
    def test_08(self):
        # Bacon path, small database, path does not exist
        actor_id = 2876669
        expected = None

        first_result = lab.bacon_path(self.db_small, actor_id)
        self.assertEqual(first_result, expected)

        second_result = lab.bacon_path(self.db_small, actor_id)
        self.assertEqual(second_result, expected)
Ejemplo n.º 4
0
def test_bacon_path_01():
    # Bacon path, small database, path does not exist
    actor_id = 2876669
    expected = None

    first_result = lab.bacon_path(db_small, actor_id)
    assert first_result == expected

    second_result = lab.bacon_path(db_small, actor_id)
    assert second_result == expected
Ejemplo n.º 5
0
 def test_12(self):
     # Bacon path, large database, length of 6 (7 actors, 6 movies)
     actor_id = 1345462
     len_expected = 6
     result = lab.bacon_path(self.db_large, actor_id)
     # here, we compute the result twice, to test for mutation of the db
     result = lab.bacon_path(self.db_large, actor_id)
     len_result = -1 if result is None else len(result) - 1
     self.assertTrue(valid_path(self.db_large, result))
     self.assertEqual(len_result, len_expected)
     self.assertEqual(result[0], 4724)
     self.assertEqual(result[-1], actor_id)
Ejemplo n.º 6
0
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())
Ejemplo n.º 7
0
def test_tiny_bacon_path():
    # Bacon path w/ tiny database
    actor_id = 1640
    expected = [4724, 2876, 1640]

    result = lab.bacon_path(db_tiny, actor_id)
    assert result == expected
Ejemplo n.º 8
0
def test_bacon_path_03():
    # Bacon path, large database, length of 2 (3 actors, 2 movies)
    actor_id = 1204
    len_expected = 2
    result = lab.bacon_path(db_large, actor_id)

    check_valid_path(raw_db_large, result, 4724, actor_id, len_expected)
Ejemplo n.º 9
0
def test_bacon_path_04():
    # Bacon path, large database, length of 4 (5 actors, 4 movies)
    actor_id = 197897
    len_expected = 4
    result = lab.bacon_path(db_large, actor_id)

    check_valid_path(raw_db_large, result, 4724, actor_id, len_expected)
Ejemplo n.º 10
0
 def test_11(self):
     # Bacon path, large database, length of 4 (5 actors, 4 movies)
     actor_id = 197897
     len_expected = 4
     result = lab.bacon_path(self.db_large, actor_id)
     len_result = -1 if result is None else len(result) - 1
     self.assertTrue(valid_path(self.db_large, result))
     self.assertEqual(len_result, len_expected)
     self.assertEqual(result[0], 4724)
     self.assertEqual(result[-1], actor_id)
Ejemplo n.º 11
0
    def test_09(self):
        # Bacon path, small database, length of 3 (4 actors, 3 movies)
        actor_id = 46866
        len_expected = 3

        first_result = lab.bacon_path(self.db_small, actor_id)
        len_first_result = -1 if first_result is None else len(
            first_result) - 1
        second_result = lab.bacon_path(self.db_small, actor_id)
        len_second_result = -1 if second_result is None else len(
            second_result) - 1

        self.assertTrue(valid_path(self.db_small, first_result))
        self.assertEqual(len_first_result, len_expected)
        self.assertEqual(first_result[0], 4724)
        self.assertEqual(first_result[-1], actor_id)

        self.assertTrue(valid_path(self.db_small, second_result))
        self.assertEqual(len_second_result, len_expected)
        self.assertEqual(second_result[0], 4724)
        self.assertEqual(second_result[-1], actor_id)
Ejemplo n.º 12
0
def bacon_path(d):
    return lab.bacon_path(small_data, d["actor_name"])
Ejemplo n.º 13
0
def test_bacon_path_custom():
    # Kevin Bacon to Blaze Kelly Coyle
    actor_id = 1386732
    result = lab.bacon_path(db_large, actor_id)
    assert result == [4724, 10742, 47773, 22865, 22866, 1386732]
Ejemplo n.º 14
0
 def test_13(self):
     # Bacon path, large database, does not exist
     actor_id = 1532
     result = lab.bacon_path(self.data, actor_id)
     expected = [4724, 1532]
     self.assertEqual(result, expected)
Ejemplo n.º 15
0
def test_bacon_path_06():
    # Bacon path, large database, does not exist
    actor_id = 1204555
    expected = None
    result = lab.bacon_path(db_large, actor_id)
    assert result == expected
Ejemplo n.º 16
0
 def test_06(self):
     self.assertTrue([4724, 2876, 1640] == lab.bacon_path(self.data, 1640))
Ejemplo n.º 17
0
def test_bacon_path_tiny():
    actor_id = 1640
    len_expected = 2

    result = lab.bacon_path(db_tiny, actor_id)
    check_valid_path(fset_tiny, result, 4724, actor_id, len_expected)
Ejemplo n.º 18
0
 def test_13(self):
     # Bacon path, large database, does not exist
     actor_id = 1204555
     expected = None
     result = lab.bacon_path(self.db_large, actor_id)
     self.assertEqual(result, expected)
Ejemplo n.º 19
0
    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')
    else:
        if path == '/':
Ejemplo n.º 20
0
    def test_f(self):
        expected = [4724, 2876, 1640]
        actor_id = 1640
        result = lab.bacon_path(self.data, actor_id)

        self.assertEqual(result, expected)
Ejemplo n.º 21
0
def test_tiny_bacon_path():
    # Bacon path, small database, path does not exist
    actor_id = 1640
    expected = [4724, 2876, 1640]
    assert lab.bacon_path(db_tiny, actor_id) == expected