def test_no_actor_movie_content():
    '''Test for a file without any movie/actor content.
    '''

    empty_actor_data = open("empty_actor_data.txt")

    assert bacon_functions.parse_actor_data(empty_actor_data) == {}, \
    'Test for basic structure of actor/movie content.'
예제 #2
0
def test_no_actor_movie_content():
    '''Test for a file without any movie/actor content.
    '''
    
    empty_actor_data = open("empty_actor_data.txt")
    
    assert bacon_functions.parse_actor_data(empty_actor_data) == {}, \
    'Test for basic structure of actor/movie content.'
def test_for_footer():
    '''Test to check if the footer is parsed correctly.
    '''

    footer_actor_data = open("footer_actor_data.txt")
    correct_dict = {'Lucien Littlefield': ['A Blonde for a Night (1928)']}

    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(footer_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for footer of actor data'
def test_for_header():
    '''Test to check if the header is parsed correctly.
    '''

    header_actor_data = open("header_actor_data.txt")
    correct_dict = {'George Petrie': ["A Fire in the Sky (1978)"]}

    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(header_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for header of actor data'
예제 #5
0
def test_for_multiple_movies():
    '''Test for actor data containing an actor with multiple common movie names.
    '''
    
    multiple_movie_actor_data = open('multiple_movie_actor_data.txt')
    correct_dict = { 'George Petrie': ['A Fire in the Sky (1978)'] }
    
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(multiple_movie_actor_data)
    sort_dict_values(program_output)
    
    assert program_output == correct_dict, \
    'Test for actors with multiple common movie names.'
예제 #6
0
def test_for_header():
    '''Test to check if the header is parsed correctly.
    '''
    
    header_actor_data = open("header_actor_data.txt")
    correct_dict = { 'George Petrie': ["A Fire in the Sky (1978)"] }
    
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(header_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for header of actor data'
예제 #7
0
def test_for_footer():
    '''Test to check if the footer is parsed correctly.
    '''
    
    footer_actor_data = open("footer_actor_data.txt")
    correct_dict = { 'Lucien Littlefield': ['A Blonde for a Night (1928)'] }
    
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(footer_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for footer of actor data'
예제 #8
0
def test_no_comma_in_actor_name():
    '''Test for actor data containing actor's name without any commas.
    '''
    
    no_comma_actor_data = open('no_comma_actor_data.txt')
    correct_dict = { 'Elvis': ['Rubber Johnny (2005)'],
                     'Ll Cool J': ['10th Anniversary Essence Awards (1997)',
                     '17th Annual Screen Actors Guild Awards (2011)'] }
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(no_comma_actor_data)
    sort_dict_values(program_output)
    
    assert program_output == correct_dict, \
    'Test for actor names without commas.'
def test_for_multiple_movies():
    '''Test for actor data containing an actor with multiple common movie names.
    '''

    multiple_movie_actor_data = open('multiple_movie_actor_data.txt')
    correct_dict = {'George Petrie': ['A Fire in the Sky (1978)']}

    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(
        multiple_movie_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for actors with multiple common movie names.'
예제 #10
0
def test_actor_with_roman_numerals():
    '''Test for actor data containing actor's name with roman numerals.
    '''
    
    roman_numeral_actor_data = open('roman_numeral_data.txt')
    correct_dict = { 'Joey Adams': ['Duress (2009)', '"Bones" (2005)',
                    '"Karen Sisco" (2003)', '"Law & Order" (1990)',
                    '"Numb3rs" (2005)'] }
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(roman_numeral_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for actor name with roman numerals.'
예제 #11
0
def test_multiple_actors():
    '''Test for actor data containing multiple actors with the same name.
    '''
    
    multiple_actor_data = open('multiple_actor_data.txt')
    correct_dict = { 'James Morrison': ['Return to Area 51 (2002)',
                    'The 32nd Annual TV Week Logie Awards (1990)',
                    'Bordellet (1972)'] }
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(multiple_actor_data)
    sort_dict_values(program_output)
    
    assert program_output == correct_dict, \
    "Test for multiple actors' names."
예제 #12
0
def test_for_middle_name_actors():
    '''Test for actor data containing actor's with middle names.
    '''
    
    middle_name_actor_data = open('middle_name_actor_data.txt')
    correct_dict = { 'Richard Dean Anderson': ['05 Spaceys (2005)',
                     '06 Spaceys (2006)'],
                     'Robert De Niro': ['Showtime (2002)',
                     'Sleepers (1996)'] }
    
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(middle_name_actor_data)
    sort_dict_values(program_output)
    
    assert program_output == correct_dict, \
    'Test for actors with middle names.'
def test_for_middle_name_actors():
    '''Test for actor data containing actor's with middle names.
    '''

    middle_name_actor_data = open('middle_name_actor_data.txt')
    correct_dict = {
        'Richard Dean Anderson': ['05 Spaceys (2005)', '06 Spaceys (2006)'],
        'Robert De Niro': ['Showtime (2002)', 'Sleepers (1996)']
    }

    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(middle_name_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for actors with middle names.'
def test_multiple_actors():
    '''Test for actor data containing multiple actors with the same name.
    '''

    multiple_actor_data = open('multiple_actor_data.txt')
    correct_dict = {
        'James Morrison': [
            'Return to Area 51 (2002)',
            'The 32nd Annual TV Week Logie Awards (1990)', 'Bordellet (1972)'
        ]
    }
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(multiple_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    "Test for multiple actors' names."
def test_actor_with_roman_numerals():
    '''Test for actor data containing actor's name with roman numerals.
    '''

    roman_numeral_actor_data = open('roman_numeral_data.txt')
    correct_dict = {
        'Joey Adams': [
            'Duress (2009)', '"Bones" (2005)', '"Karen Sisco" (2003)',
            '"Law & Order" (1990)', '"Numb3rs" (2005)'
        ]
    }
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(roman_numeral_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for actor name with roman numerals.'
예제 #16
0
def test_for_movie_spanning_multiple_lines():
    '''Test for actor data containing an actor with a movie spanning over
    multiple lines.
    '''
    
    spanning_movie_actor_data = open('spanning_movie_actor_data.txt')
    correct_dict = { 'Frankie Avalon': ['"Live Wednesday" (1978)',
                    '"Love, American Style" (1969)'],
                     'Stephen Baldwin': ['"Clerks" (2000)'],
                    'Jim Byrnes': ['The 53rd Annual Golden Globe Awards (1996)'] }
    
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(spanning_movie_actor_data)
    sort_dict_values(program_output)
    
    assert program_output == correct_dict, \
    'Test for actors with movie spanning multiple lines.'
def test_no_comma_in_actor_name():
    '''Test for actor data containing actor's name without any commas.
    '''

    no_comma_actor_data = open('no_comma_actor_data.txt')
    correct_dict = {
        'Elvis': ['Rubber Johnny (2005)'],
        'Ll Cool J': [
            '10th Anniversary Essence Awards (1997)',
            '17th Annual Screen Actors Guild Awards (2011)'
        ]
    }
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(no_comma_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for actor names without commas.'
예제 #18
0
def test_basic_actor_data():
    '''Test for a file with basic actor/movie content.
    '''
        
    basic_actor_data = open("basic_actor_data.txt")
    correct_dict = { 'Al Gore': ["'Hick' Town (2009)",
                    "Hillary! Uncensored: Banned by the Media (2008)",
                    "Johnny Cash's America (2008)",
                    "Journeys with George (2002)",
                    "Last Days on Earth (2006)"],
                    'Jon Langford': ["At Last, Okemah! (2009)",
                    "Cavedweller (2004)",
                    "Johnny Cash's America (2008)"] }
    
    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(basic_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for basic structure of actor/movie content.'
def test_for_movie_spanning_multiple_lines():
    '''Test for actor data containing an actor with a movie spanning over
    multiple lines.
    '''

    spanning_movie_actor_data = open('spanning_movie_actor_data.txt')
    correct_dict = {
        'Frankie Avalon':
        ['"Live Wednesday" (1978)', '"Love, American Style" (1969)'],
        'Stephen Baldwin': ['"Clerks" (2000)'],
        'Jim Byrnes': ['The 53rd Annual Golden Globe Awards (1996)']
    }

    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(
        spanning_movie_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for actors with movie spanning multiple lines.'
def test_basic_actor_data():
    '''Test for a file with basic actor/movie content.
    '''

    basic_actor_data = open("basic_actor_data.txt")
    correct_dict = {
        'Al Gore': [
            "'Hick' Town (2009)",
            "Hillary! Uncensored: Banned by the Media (2008)",
            "Johnny Cash's America (2008)", "Journeys with George (2002)",
            "Last Days on Earth (2006)"
        ],
        'Jon Langford': [
            "At Last, Okemah! (2009)", "Cavedweller (2004)",
            "Johnny Cash's America (2008)"
        ]
    }

    sort_dict_values(correct_dict)
    program_output = bacon_functions.parse_actor_data(basic_actor_data)
    sort_dict_values(program_output)

    assert program_output == correct_dict, \
    'Test for basic structure of actor/movie content.'
예제 #21
0
Bacon, Kevin			A Few Good Men (1992)  [Capt. Jack Ross]  <4>

De Niro, Robert			Sleepers (1996)	 [Father Bobby]  <3>

-----------------------------------------------------------------------------

SUBMITTING UPDATES
==================

CUTTING UPDATES

For further info visit http://www.imdb.com/licensing/contact
''')
      expected = {"Kevin Bacon": ["A Few Good Men (1992)"],
                "Robert De Niro": ["Sleepers (1996)"]}
      result = bacon_functions.parse_actor_data(reader)
      if expected != result:
          print "Failure of function parse_actor_data: " + \
                "Result should be %s, not %s" % (str(expected), str(result))
          ok = False
   else:
      print "Function 'parse_actor_data' is not defined"
      ok = False
       
   if hasattr(bacon_functions, 'invert_actor_dict'):
      expected = {"A Few Good Men (1992)": ["Kevin Bacon"],
                  "Sleepers (1996)": ["Kevin Bacon"]}
      result = bacon_functions.invert_actor_dict({"Kevin Bacon": ["A Few Good Men (1992)",
                                                        "Sleepers (1996)"]})
      if expected != result:
          print "Failure of function invert_actor_dict: " + \
예제 #22
0
import bacon_functions

filename = open("large_actor_data.txt")
actor_dict = bacon_functions.parse_actor_data(filename)
movie_dict = bacon_functions.invert_actor_dict(actor_dict)

c = 0
empty = [0]

while c >= 0:

    actor_name = raw_input(\
        "Please enter an actor (or press return to exit): ")
    actor_name = actor_name.title()

    if actor_name == "":

        # If an empty string was entred, we need to present the largest bacon
        # number that has been found. Because we collect all the bacon numbers
        # in a list, we just need to sort it and find the maxium number, which
        # is the last number. Then the whole game stopped.

        empty.sort()
        maxium = empty[-1]
        leave = "Thank you for playing! " + \
        "The largest Bacon Number you found was " + str(maxium)
        print leave
        print ''
        c = -1
        # -1 stopped the function from continuing.
예제 #23
0
import bacon_functions

if __name__ == '__main__':
    actor_data = open('large_actor_data.txt','r')
    
    # Changes the actor_data and actor_dict into dictionaries that we can use
    actor_dict = bacon_functions.parse_actor_data(actor_data)
    movie_dict = bacon_functions.invert_actor_dict(actor_dict)   
    
    counter = 'continue'
    bacon_number_list = []
    
    while counter == 'continue':
    # As long as counter is 'continue', while loop will continue running
        
        # Take the raw input and remove all unnecessary spaces
        actor_name = raw_input\
                   ('Please enter an actor (or press return to exit): ').strip()
        if actor_name != '':
            
            # If Kevin Bacon is not in the list and he is being searched, print
            # bacon number is infinity and gets rid of roman numerals
            if 'Kevin Bacon' == bacon_functions.fix_actor_name(actor_name) and\
               'Kevin Bacon' not in actor_dict: 
                print 'Kevin Bacon has a Bacon Number of Infinity.' + '\n'
                
            # Exception: if the title of actor_name is 'Kevin Bacon', 
            # return 0 as the Bacon Number. (gets rid of roman numerals)           
            elif bacon_functions.fix_actor_name(actor_name) == 'Kevin Bacon':
                print bacon_functions.fix_actor_name(actor_name) + \
                      ' has a Bacon Number of 0.' + '\n'
예제 #24
0
De Niro, Robert			Sleepers (1996)	 [Father Bobby]  <3>

-----------------------------------------------------------------------------

SUBMITTING UPDATES
==================

CUTTING UPDATES

For further info visit http://www.imdb.com/licensing/contact
''')
        expected = {
            "Kevin Bacon": ["A Few Good Men (1992)"],
            "Robert De Niro": ["Sleepers (1996)"]
        }
        result = bacon_functions.parse_actor_data(reader)
        if expected != result:
            print "Failure of function parse_actor_data: " + \
                  "Result should be %s, not %s" % (str(expected), str(result))
            ok = False
    else:
        print "Function 'parse_actor_data' is not defined"
        ok = False

    if hasattr(bacon_functions, 'invert_actor_dict'):
        expected = {
            "A Few Good Men (1992)": ["Kevin Bacon"],
            "Sleepers (1996)": ["Kevin Bacon"]
        }
        result = bacon_functions.invert_actor_dict(
            {"Kevin Bacon": ["A Few Good Men (1992)", "Sleepers (1996)"]})
예제 #25
0
파일: bacon.py 프로젝트: DevonWelch/School
import bacon_functions

filename = open("large_actor_data.txt")
actor_dict = bacon_functions.parse_actor_data(filename)
movie_dict = bacon_functions.invert_actor_dict(actor_dict)

c = 0
empty = [0]

while c >= 0:
    
    actor_name = raw_input(\
        "Please enter an actor (or press return to exit): ")
    actor_name = actor_name.title()
    
    if actor_name == "":
        
        # If an empty string was entred, we need to present the largest bacon
        # number that has been found. Because we collect all the bacon numbers
        # in a list, we just need to sort it and find the maxium number, which
        # is the last number. Then the whole game stopped.
        
        empty.sort()
        maxium = empty[-1]
        leave = "Thank you for playing! " + \
        "The largest Bacon Number you found was " + str(maxium)
        print leave
        print ''
        c = -1
        # -1 stopped the function from continuing.
예제 #26
0
import cPickle

import bacon_functions


def pickle_dump(obj, file_name):
    f = open(file_name, 'w')
    cPickle.dump(obj, f)
    f.close()


if __name__ == "__main__":
    # Parsing file of actors (male)
    imdb_actors_file = open("actors.list")
    print('Parsing file (actors.list) of actors (male) ...')
    actors_dict = bacon_functions.parse_actor_data(imdb_actors_file)
    imdb_actors_file.close()

    # Parsing file of actors (female)
    imdb_actresses_file = open("actresses.list")
    print('Parsing file (actresses.list) of actresses (female) ...')
    actresses_dict = bacon_functions.parse_actor_data(imdb_actresses_file)
    imdb_actresses_file.close()

    # thanks for the quick reminder: http://stackoverflow.com/a/38990
    # Merging both the (actors to movies) data structures
    print('Merging both the (actors to movies) data structures ...')
    actors_to_movies = dict(actors_dict.items() + actresses_dict.items())

    # Creating a movies to actors data structure
    print('Creating a movies to actors data structure ...')
예제 #27
0
파일: make_bacon.py 프로젝트: kod3r/bacon
import cPickle

import bacon_functions


def pickle_dump(obj, file_name):
    f = open(file_name, "w")
    cPickle.dump(obj, f)
    f.close()


if __name__ == "__main__":
    # Parsing file of actors (male)
    imdb_actors_file = open("actors.list")
    print "Parsing file (actors.list) of actors (male) ..."
    actors_dict = bacon_functions.parse_actor_data(imdb_actors_file)
    imdb_actors_file.close()

    # Parsing file of actors (female)
    imdb_actresses_file = open("actresses.list")
    print "Parsing file (actresses.list) of actresses (female) ..."
    actresses_dict = bacon_functions.parse_actor_data(imdb_actresses_file)
    imdb_actresses_file.close()

    # thanks for the quick reminder: http://stackoverflow.com/a/38990
    # Merging both the (actors to movies) data structures
    print "Merging both the (actors to movies) data structures ..."
    actors_to_movies = dict(actors_dict.items() + actresses_dict.items())

    # Creating a movies to actors data structure
    print "Creating a movies to actors data structure ..."