def interpret(self): """Interprets the code in this Console. Due to inconsistencies with sqlite3 and Python's bindings, the following process is used to interpret code: 1. If the Python sqlite3 module has an up-to-date binding (compared to self.VERSION), interpret line-by-line with full output validation. 2. Otherwise, if there is an executable called "sqlite3" (in the current directory is okay), pipe the test case into sqlite3 and display expected and actual output. No output validation is available; students have to verify their solutions manually. 3. Otherwise, report an error. """ if self._import_sqlite(): self._conn = self.sqlite3.connect(':memory:', check_same_thread=False) return super().interpret() env = dict(os.environ, PATH=os.getcwd() + os.pathsep + os.environ["PATH"]) if self._has_sqlite_cli(env): print( 'Unfortunately, OK is unable to use sqlite3 to test your code directly.' ) print( 'Here is a transcript of what your code does in the sqlite3 interpreter.' ) print() test, expected, result = self._use_sqlite_cli(env) print('TEST:') print(format.indent(test, ' ')) print('EXPECTED (order does not matter):') print(format.indent(expected, ' ')) print('OUTPUT:') print(format.indent(result, ' ')) print() print( "Please manually check if your solution's output is correct.") return False else: print("ERROR: could not run sqlite3.") print( "Tests will not pass, but you can still submit your assignment." ) print( "Please download the newest version of sqlite3 into this folder" ) print("to run tests.") return False
def interpret(self): """Interprets the code in this Console. If there is an executable called "sqlite3" (in the current directory is okay), pipe the test case into sqlite3. Otherwise, report an error. """ env = dict(os.environ, PATH=os.getcwd() + os.pathsep + os.environ['PATH']) if self._has_sqlite_cli(env): try: test, expected, actual = self._use_sqlite_cli(env) except interpreter.ConsoleException: return False print(format.indent(test, 'sqlite> ')) # TODO: show test with prompt print(actual) try: self._diff_output(expected, actual) return True except interpreter.ConsoleException: return False else: print('ERROR: could not run sqlite3.') print('Tests will not pass, but you can still submit your assignment.') print('Please download the newest version of sqlite3 into this folder') print('to run tests.') return False
def interpret(self): """Interprets the code in this Console. If there is an executable called "sqlite3" (in the current directory is okay), pipe the test case into sqlite3. Otherwise, report an error. """ env = dict(os.environ, PATH=os.getcwd() + os.pathsep + os.environ['PATH']) if self._has_sqlite_cli(env): try: test, expected, actual = self._use_sqlite_cli(env) except interpreter.ConsoleException: return False print(format.indent(test, 'sqlite> ')) # TODO: show test with prompt print(actual) try: self._diff_output(expected, actual) return True except interpreter.ConsoleException: return False else: print('ERROR: could not run sqlite3.') print( 'Tests will not pass, but you can still submit your assignment.' ) print( 'Please download the newest version of sqlite3 into this folder' ) print('to run tests.') return False
def interpret(self): """Interprets the code in this Console. Due to inconsistencies with sqlite3 and Python's bindings, the following process is used to interpret code: 1. If the Python sqlite3 module has an up-to-date binding (compared to self.VERSION), interpret line-by-line with full output validation. 2. Otherwise, if there is an executable called "sqlite3" (in the current directory is okay), pipe the test case into sqlite3 and display expected and actual output. No output validation is available; students have to verify their solutions manually. 3. Otherwise, report an error. """ if self._import_sqlite(): self._conn = self.sqlite3.connect(':memory:', check_same_thread=False) return super().interpret() env = dict(os.environ, PATH=os.getcwd() + os.pathsep + os.environ["PATH"]) if self._has_sqlite_cli(env): test, expected, actual = self._use_sqlite_cli(env) print(format.indent(test, 'sqlite> ')) # TODO: show test with prompt print(actual) try: self._diff_output(expected, actual) return True except interpreter.ConsoleException: return False else: print("ERROR: could not run sqlite3.") print("Tests will not pass, but you can still submit your assignment.") print("Please download the newest version of sqlite3 into this folder") print("to run tests.") return False
def _display_choices(self, choices): """Prints a mapping of numbers to choices and returns the mapping as a dictionary. """ print("Choose the number of the correct choice:") choice_map = {} for i, choice in enumerate(choices): i = str(i) print('{}) {}'.format(i, format.indent(choice, ' ' * (len(i) + 2)).strip())) choice = format.normalize(choice) choice_map[i] = choice return choice_map
def interpret(self): """Interprets the code in this Console. Due to inconsistencies with sqlite3 and Python's bindings, the following process is used to interpret code: 1. If the Python sqlite3 module has an up-to-date binding (compared to self.VERSION), interpret line-by-line with full output validation. 2. Otherwise, if there is an executable called "sqlite3" (in the current directory is okay), pipe the test case into sqlite3 and display expected and actual output. No output validation is available; students have to verify their solutions manually. 3. Otherwise, report an error. """ if self._import_sqlite(): self._conn = self.sqlite3.connect(':memory:', check_same_thread=False) return super().interpret() env = dict(os.environ, PATH=os.getcwd() + os.pathsep + os.environ["PATH"]) if self._has_sqlite_cli(env): print('Unfortunately, OK is unable to use sqlite3 to test your code directly.') print('Here is a transcript of what your code does in the sqlite3 interpreter.') print() test, expected, result = self._use_sqlite_cli(env) print('TEST:') print(format.indent(test, ' ')) print('EXPECTED (order does not matter):') print(format.indent(expected, ' ')) print('OUTPUT:') print(format.indent(result, ' ')) print() print("Please manually check if your solution's output is correct.") return False else: print("ERROR: could not run sqlite3.") print("Tests will not pass, but you can still submit your assignment.") print("Please download the newest version of sqlite3 into this folder") print("to run tests.") return False
def _display_choices(self, choices): """Prints a mapping of numbers to choices and returns the mapping as a dictionary. """ print("Choose the number of the correct choice:") choice_map = {} for i, choice in enumerate(choices): i = str(i) print('{}) {}'.format(i, format.indent(choice, ' ' * (len(i) + 2)).strip())) choice = format.normalize(choice) choice_map[i] = choice return choice_map