Package: school-grader
Python Student Testing FrameworkContentsIntroductionFeaturesInstallationContributingLicenseContactHow to useExtension for Visual Studio CodeIntroductionWelcome to the Python Student Testing Framework! This README provides a brief overview of what the framework is and how to use it. The framework is designed for instructors and TAs to easily test and grade students Python code.FeaturesAutomated testing of students' code against a set of test casesSupport for multiple test cases and multiple functionsAbility to define custom tests and assertionsClear and detailed feedback for students on test resultsDisplay HTML reportInstallationTo use the Python Student Testing Framework, you will need to have Python installed on your machine. Then, simply clone the repository or install withpip install school-graderContributingThe Python Student Testing Framework is an open-source project and contributions are welcome.LicenseThe Python Student Testing Framework is released under the MIT license. See the LICENSE file for more information.ContactIf you have any questions or issues, please create a GitHub issue or reach out to the project maintainers atmarcolivier.derouin@poulet-frit.comHow to useLet's say you have given an assignment to your students.assignment1.pywords=input("Please enter a list of words separated by spaces: ").split(" ")palindrome_words=[]non_palindrome_words=[]forwordinwords:lowercase_word=word.lower()iflowercase_word==lowercase_word[::-1]:palindrome_words.append(word)else:non_palindrome_words.append(word)print("Palindrome words:"+" ".join(palindrome_words))print("Non-palindrome words:"+" ".join(non_palindrome_words))You can write test case for this assignment using the following code.fromschool_graderimportFileTestCase,run_testsFileTestCase('Test #1',# Test name'assignment1',# File name['Palindrome words:kayak','Non-palindrome words:hi bonjour'],# Expected output, in a list of strings, each element is a printed line['kayak hi bonjour'],# Mock input, in a list of strings, each element is a input line)FileTestCase('Test #2','assignment1',['Palindrome words:level racecar madam level','Non-palindrome words:'],['level racecar madam level'],# This parameter is optional, if not provided, the test will input nothing)FileTestCase('Test #3','assignment1',['Palindrome words:','Non-palindrome words:hello world goodbye'],['hello world goodbye'],timeout=4,# This parameter is optional, if not provided, the test will timeout after 1 second)FileTestCase('Test #4','assignment1',['Palindrome words:KAyak','Non-palindrome words:hello world goodbye'],['hello world goodbye KAyak'],fail_message='Did you think about case sensitivity?',# This parameter is optional, if not provided, the test will fail with a default message)run_tests()This will generate an HTML report that will automatically open in the browser.If there is an error in the student code, the report will look like this.Expected outputsThe expected_output list in FileTestCase can also contains an Equality class object in order to help with string comparisonAlmost equalAlmostEqualString: This class is used for almost equal string validation:expected: The expected string value for comparison.max_distance: The maximum Levenshtein distance allowed between the expected value and the value to test.AlmostEqualNumber: This class is used for almost equal numerical validation:expected: The expected string value for comparison.precision: The number of decimal places to compare for floating-point numbers.EqualCaseInsensitiveStringEquality: This class is used for case-insensitive string equality validation:expected: The expected string value for comparison.WhiteSpaceInsensitiveEquality: This class is used for space-insensitive equality validation:expected: The expected string value for comparison.ContainsEquality: This class is used for contains equality validation:expected: The expected string value to check if it is contained in the value to test.Combinations of Equal classesCombineEqualities(): This function combines multiple instances ofEqualsubclasses and returns a new subclass that combines all the provided equalities.Here is an example using CaseInsentiveStringEqualityfromschool_graderimportFileTestCase,run_tests,CaseInsensitiveStringEqualityFileTestCase('Test #1',# Test name'assignment1',# File name[CaseInsensitiveStringEquality('palindrome words:kayak'),CaseInsensitiveStringEquality('non-palindrome words:hi bonjour')],# Expected output['kayak hi bonjour'],# Mock input, in a list of strings, each element is a input line)run_tests()# Run all testsHere is an example combining CaseInsentiveStringEquality and WhiteSpaceInsensitiveEqualityfromschool_graderimportFileTestCase,run_tests,CaseInsensitiveStringEquality,WhiteSpaceInsensitiveEquality,CombineEqualitiesInsentive=CombineEqualities(CaseInsensitiveStringEquality,WhiteSpaceInsensitiveEquality)FileTestCase('Test #1',# Test name'assignment1',# File name[Insentive('palindromewords:kayak'),Insentive('non-palindromewords:hibonjour')],# Expected output['kayak hi bonjour'],# Mock input, in a list of strings, each element is a input line)run_tests()# Run all testsExtension for Visual Studio CodeYou can download a Visual Studio Code extension that will provide coloring when running tests.print('Hi')You can run the tests with these buttons.The result will look like this. When you hover on a test, you will see the Stack trace.