Skip to content

Instantly share code, notes, and snippets.

@pazz
Last active July 4, 2020 19:01
Show Gist options
  • Save pazz/f109183b56cf8919e1efd358f3b7cc9a to your computer and use it in GitHub Desktop.
Save pazz/f109183b56cf8919e1efd358f3b7cc9a to your computer and use it in GitHub Desktop.
import check50
import check50java
REPORT = {'testcases': [
{'name': 'getPriceFails',
'classname': 'ItemTest',
'time': '0.035',
'pass': False,
'message': 'Item has no constructor for argument java.lang.String, int, int'},
{'name': 'testToString',
'classname': 'ItemTest',
'time': '0.001',
'pass': False,
'message': 'Item has no constructor for argument java.lang.String, int, int'},
{'name': 'pricePerUnitWeight',
'classname': 'ItemTest',
'time': '0.001',
'pass': False,
'message': 'Item has no constructor for argument java.lang.String, int, int'},
{'name': 'getDescription',
'classname': 'ItemTest',
'time': '0.001',
'pass': False,
'message': 'Item has no constructor for argument java.lang.String, int, int'},
{'name': 'getPrice',
'classname': 'ItemTest',
'time': '0.002',
'pass': False,
'message': 'Item has no constructor for argument java.lang.String, int, int'}
],
'failures': 0,
'tests': 5,
'passed': 5
}
@check50.check()
def item_exists():
"""Item.java exists."""
check50.exists("Item.java")
@check50.check(item_exists)
def item_compiles():
"""Item.java compiles."""
check50java.compile("Item.java")
@check50.check(item_exists)
def run_tests():
"""ItemTest"""
# check50.include('tests/ItemTest.class')
#report = check50java.junit5.run_test('ItemTest')
# check50._api.log(str(report))
return REPORT
def create_check(testclass, i):
def check(rep):
check50._api.log(str(len(rep['testcases'])))
check50._api.log(str(i))
return rep
check.__name__ = f"{i}"
check.__doc__ = f"{check_id} passes"
return check
# Copy compiled test class into student's submission
check50.include('tests/ItemTest.class')
testclass = "itemTest"
# run junit once to generate report and extract test cases
# report = check50java.junit5.run_test(testclass)
report = REPORT # for now
i = 0
for case in report['testcases']:
testmethod = case['name']
check_id = f"{testclass}__{testmethod}"
check = create_check(testclass, i)
i += 1
# Register the check with check50
check = check50.check(run_tests)(check)
# Add the check to global module scope
globals()[check_id] = check
@pazz
Copy link
Author

pazz commented Jul 4, 2020

Full output:

Checking...
Results for /home/pazz/repo/teaching/2020-COMP122-OOP/assessment/tmp/resit/pset generated by check50 v3.1.2
:) Item.java exists.
    checking that Item.java exists...
:) Item.java compiles.
    running javac -classpath "."  Item.java...
:) ItemTest
:) ItemTest__getPriceFails passes
    5
    0
:) ItemTest__testToString passes
    5
    1
:) ItemTest__pricePerUnitWeight passes
    5
    2
:) ItemTest__getDescription passes
    5
    3
:| ItemTest__getPrice passes
    check50 ran into an error while running checks!
    FileExistsError: [Errno 17] File exists: '/tmp/tmpcyjf72sn/4'
      File "/home/pazz/.local/lib/python3.8/site-packages/check50/runner.py", line 136, in wrapper
    shutil.copytree(src_dir, internal.run_dir)
      File "/usr/lib/python3.8/shutil.py", line 554, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
      File "/usr/lib/python3.8/shutil.py", line 455, in _copytree
    os.makedirs(dst, exist_ok=dirs_exist_ok)
      File "/usr/lib/python3.8/os.py", line 223, in makedirs
    mkdir(name, mode)
To see the results in your browser go to file:///tmp/tmpm3x89bqo.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment