def generate(file=""): if file: user_examples_list = e.from_file(file) else: # Write the user's examples from the request object into a file. # request.form window.form['examples_f'].div['examples_edit'] user_examples = request.form['examples_i'] # return "<!DOCTYPE html><html lang='en'><body>" + str(user_examples) + "</body></html>" name = request.form['function_name'] if name and name != 'NameYourFunctionHere': file = name + ".exem" # User-specified function name else: file = 'e' + str( random.randrange(10)) + ".exem" # Pick a name at random. e.to_file(file, user_examples) # Write to it. user_examples_list = user_examples.split('\n') code, test_file_contents = e.reverse_trace( file) # Capture code for display. # return "<!DOCTYPE html><html lang='en'><body>" + str(len(code)) + "</body></html>" return html(user_examples_list, code, test_file_contents)
def test_sum_double(self): code, test_file_contents = exemplar.reverse_trace("sum_double.exem") assert """def sum_double(): int1 = int(input("int1:")) # Eg, 1""" in code # First 2 lines of generated function. assert "# The generated function under Stage 2" in test_file_contents
def test_monkey_trouble(self): code, test_file_contents = exemplar.reverse_trace( "monkey_trouble.exem") assert """def monkey_trouble(): a_smile = int(input("a_smile:")) # Eg, 1""" in code # First 2 lines of generated function. assert "# The generated function under Stage 2" in test_file_contents
def test_sleep_in(self): code, test_file_contents = exemplar.reverse_trace("sleep_in.exem") assert """def sleep_in(): weekday = int(input("weekday:")) # Eg, 0""" in code assert "# The generated function under Stage 2" in test_file_contents
def test_guess4(self): code, test_file_contents = exemplar.reverse_trace("guess4.exem") assert """def guess4(): print('Hello! What is your name?')""" in code assert "# The generated function under Stage 2" in test_file_contents
def test_prime_number(self): code, test_file_contents = exemplar.reverse_trace("prime_number.exem") assert """def prime_number(): inp = int(input("inp:"))""" in code assert "# The generated function under Stage 2" in test_file_contents
def test_leap_year(self): code, test_file_contents = exemplar.reverse_trace("leap_year.exem") assert """def leap_year(): i1 = int(input("i1:"))""" in code assert "# The generated function under Stage 2" in test_file_contents