def test_one(): expected = """This is a short story of {noun}'s life. He {verb} to ASAC {adverb} with his family's {noun}. but When he has a conflict with his family, he goes by {noun}. too bad that he felt {adjective} last {noun} because he went daily by his {noun}. on the occasion of this short story of {noun}'s life; he still like programming. """ actual = read_template(open('assets/text.txt')) assert expected.strip() == actual
def test_list(): actual = find_words("\{(.*?)\}", read_template('assets/madlib.txt')) expected = [ 'Adjective', 'Adjective', 'A First Name', 'Past Tense Verb', 'A First Name', 'Adjective', 'Adjective', 'Plural Noun', 'Large Animal', 'Small Animal', "A Girl's Name", 'Adjective', 'Plural Noun', 'Adjective', 'Plural Noun', 'Number 1-50', "First Name's", 'Number', 'Plural Noun', 'Number', 'Plural Noun' ] assert actual == expected
def test_read_template(): actual = read_template('test.txt') expect = "This is a {test}" assert actual == expect
def test_read_template_returns_stripped_string(): actual = read_template("assets/dark_and_stormy_night.txt") expected = "It was a {Adjective} and {Adjective} {Noun}." assert actual == expected
def test_read_template(): actual = read_template('./madlib_cli/assets/test_text_template.txt') expected = "I am a {adjective} {adjective} test text file!" assert actual == expected
def test_parse(): actual = parse(read_template(testName)) expect = ['{test}'] assert actual == expect
import pytest from madlib_cli.madlib import read_template, parse_template, merge_template open_sample_text = open("assets/sample.txt").read() path = "assets/sample.txt" string = read_template("assets/sample.txt") def test_read_template(): actual = read_template("assets/sample.txt") expected = open_sample_text.strip() assert actual == expected def test_parse_template(): actual_string, actual_list = parse_template(string) expected_string = "Make Me A Video Game!\n\nI the {} and {} {} have {}{}'s {} sister and plan to\nsteal her {} {}!\n\nWhat are a {} and backpacking {} to do? Before you can help {}, you'll have to collect \nthe {} {} and {} {} that open up the {} worlds connected to A {} Lair. \nThere are {} {} and {} {} in the game, along with hundreds of other goodies for you to find." expected_list = [ "Adjective", "Adjective", "A First Name", "Past Tense Verb", "A First Name", "Adjective", "Adjective", "Plural Noun", "Large Animal", "Small Animal", "A Girl's Name", "Adjective", "Plural Noun",
def testRead(): expected = open('assets/template.txt','r').read() received = read_template() assert expected == received
def test_read_template(): actual = read_template('assets/test.txt') expected = 'This is a test\nhello\nwelcome' assert actual == expected
def text_file_not_found_exception(): with pytest.raises(FileNotFoundError): file_path = "madlib_cli" read_template(file_path)
def test_read_template(): file_path = "madlib_cli" assert "I am the {noun}" in read_template(file_path)
def test_read_template(): actual = read_template(path) expected = open_file.strip() assert actual == expected
from madlib_cli.madlib import read_template, parse import re open_file = open('assets/game.txt').read() path = 'assets/game.txt' string_template = read_template('assets/game.txt') def test_read_template(): actual = read_template(path) expected = open_file.strip() assert actual == expected def test_parse(): actual = parse(string_template) expected = ''' Make Me A Video Game! I the {} and {} {} have {}{}'s {} sister and plan to steal her {} {}! What are a {} and backpacking {} to do? Before you can help {}, you'll have to collect the {} {} and {} {} that open up the {} worlds connected to A {} Lair. There are {} {} and {} {} in the game, along with hundreds of other goodies for you to find. ''' assert actual == expected
def test_read_func(): expected = open('../assets/template.txt','r').read() received = read_template() assert expected == received
def test_parse_template(): actual = parse_template(read_template('test.txt')) expect = ['test'] assert actual == expect
def test_read_with_placeholders(): actual = read_template("assets/test_with_placeholders.txt") expected = "Hello there, this is {Name}, I am {Age} years old." assert actual == expected
def test_read_template_raises_exception_with_bad_path(): with pytest.raises(FileNotFoundError) as err: path = "missing.txt" read_template(path) assert str(err.value) == "File not found"
def test_read_template_returns_stripped_string(): actual = read_template("assets/video_game.txt") expected = "I the {Adjective} and {Adjective} {A First Name}" assert actual == expected
print(""" **************************************************** Welcome. We are going to play Madlibs! You will be prompted with a series of prompts. Provde appropriate responses to complete the Madlib **************************************************** """) user_responses = [] def get_responses(): adj1 = input("Provide an Adjective ") user_responses.append(adj1) adj2 = input("Provide another Adjective ") user_responses.append(adj2) noun1 = input("Provide a Noun ") user_responses.append(noun1) madlib = read_template("assets/dark_and_stormy_night.txt") parsed_text, words = parse_template(madlib) parts = get_responses() print(user_responses) print(merge(parsed_text, user_responses))
def test_read_template(): actual = read_template( "/home/hamza/Desktop/401/labs/lab3/madlib-cli/textFiles/test.txt") expected = "Hello Gys I'm {first name} {last name} => hamza rashed" assert actual == expected
def test_read_template(): actual = read_template("assets/sample.txt") expected = open_sample_text.strip() assert actual == expected
def test_read_files(): expected = open('madlib-cli/files/story.txt', 'r').read() received = read_template() assert expected == received
def test_read_template(): actual = read_template(testName) expect = 'this is a {test}' assert actual == expect
def testRead(): actual = read_template() expected = open('assets/sample_template.txt', 'r').read() assert expected == actual
def test_read_template(): actual = isinstance(read_template('assets/madlib.txt'), str) expected = True assert actual == expected
def test_read_empty(): actual = read_template("assets/test_empty.txt") expected = "" assert actual == expected
def test_read_template_returns_stripped_string(): actual = read_template("madlib_cli/assets/easy_peasy.txt") expected = "A {Adjective} and {Adjective} {Noun}." assert actual == expected
def test_read_no_placeholders(): actual = read_template("assets/test_no_placeholders.txt") expected = "Hello there, this is Batool." assert actual == expected
def test_read_template_raises_exception_with_bad_path(): with pytest.raises(FileNotFoundError): path = "missing.txt" read_template(path)
def test_read_template(): expected = "banana" actual = read_template(" banana ") assert expected == actual