Skip to content
Snippets Groups Projects
Commit 74a8a463 authored by tuhe's avatar tuhe
Browse files

Added automatic testing of snip-tags

parent 362e8ec0
No related branches found
No related tags found
No related merge requests found
Showing
with 333 additions and 0 deletions
image: ubuntu:latest
stages:
- test
.test_snipper:
stage: test
script:
- echo "Testing student files"
# - pwd
- apt-get update -y
- apt install -y python3-pip
- apt install -y python3.10 python-is-python3
# - apt install -y python-is-python3
# - python --version
# - locate python
- apt install -y git
- apt install -y xvfb # Virtual framebuffer for GL stuff.
# - apt install -y inkscape pdftk
# - apt install -y latexmk poppler-utils # latexmk and pdftocairo
# - DEBIAN_FRONTEND='noninteractive' apt install -y texlive-latex-recommended texlive-latex-extra texlive-science pdf2svg
# - pip install -U Pillow
- pip install -e ./
- cd tests
- xvfb-run -s "-screen 0 1400x900x24" python -m unittest test_python.py
- latexmk --version
- ls tests_images/*
test_39:
extends: .test_students
image: ubuntu:latest
import sys
class TreeNode(object): #!s=a
def __init__(self, x): #!s=a
self.val = x #!b=a
self.left = None
self.right = None #!b=a
#!s=a
def sorted_array_to_bst(nums):
if not nums: #!b=cuthere
return None #!s=myfile
mid_val = len(nums) // 2 #!s=a
node = TreeNode(nums[mid_val]) #!b=cuthere "Your stuff here"
node.left = sorted_array_to_bst(nums[:mid_val])
node.right = sorted_array_to_bst(nums[mid_val + 1:]) #!b # Solve this problem
return node #!b Here
print("hello world asdfasd")
#!o=a
def preOrder(node):
if not node: #!f
return
print(node.val)
preOrder(node.left)#!s=myfile
preOrder(node.right)
for _ in range(10):
print("Hello world")
#!o=a
a = 234
result = sorted_array_to_bst([1, 2, 3, 4, 5, 6, 7])
preOrder(result)
#!i=a
for _ in range(10):
print("hi")
#!i=a
#!i=b
print("hello")
def myfun(a):
return a*2
print(myfun(4))
#!i=b
\ No newline at end of file
import sys
class TreeNode(object):
def __init__(self, x):
# TODO: 3 lines missing.
raise NotImplementedError("Insert your solution and remove this error.")
#!s=a
def sorted_array_to_bst(nums):
# TODO: 4 lines missing.
raise NotImplementedError("Your stuff here")
node.left = sorted_array_to_bst(nums[:mid_val])
# Solve this problem
# TODO: 2 lines missing.
raise NotImplementedError("Here")
print("hello world asdfasd")
#!o=a
def preOrder(node):
if not node:
# TODO: 1 lines missing.
raise NotImplementedError("Implement function body")
print(node.val)
preOrder(node.left)
preOrder(node.right)
for _ in range(10):
print("Hello world")
#!o=a
a = 234
result = sorted_array_to_bst([1, 2, 3, 4, 5, 6, 7])
preOrder(result)
#!i=a
for _ in range(10):
print("hi")
#!i=a
#!i=b
print("hello")
def myfun(a):
return a*2
print(myfun(4))
#!i=b
# tree.py
class TreeNode(object):
def __init__(self, x):
def sorted_array_to_bst(nums):
if not nums:
return None
mid_val = len(nums) // 2
\ No newline at end of file
>>>
>>> for _ in range(10):
... print("hi")
\ No newline at end of file
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
>>>
>>>
>>> print("hello")
hello
>>> def myfun(a):
... return a*2
...
\ No newline at end of file
# tree.py
return None
mid_val = len(nums) // 2
node = TreeNode(nums[mid_val])
node.left = sorted_array_to_bst(nums[:mid_val])
node.right = sorted_array_to_bst(nums[mid_val + 1:])
return node
print("hello world asdfasd")
#!o=a
def preOrder(node):
if not node:
return
print(node.val)
preOrder(node.left)
\ No newline at end of file
import sys
class TreeNode(object):
def __init__(self, x):
# TODO: 3 lines missing.
raise NotImplementedError("Insert your solution and remove this error.")
#!s=a
def sorted_array_to_bst(nums):
# TODO: 4 lines missing.
raise NotImplementedError("Your stuff here")
node.left = sorted_array_to_bst(nums[:mid_val])
# Solve this problem
# TODO: 2 lines missing.
raise NotImplementedError("Here")
print("hello world asdfasd")
#!o=a
def preOrder(node):
if not node:
# TODO: 1 lines missing.
raise NotImplementedError("Implement function body")
print(node.val)
preOrder(node.left)
preOrder(node.right)
for _ in range(10):
print("Hello world")
#!o=a
a = 234
result = sorted_array_to_bst([1, 2, 3, 4, 5, 6, 7])
preOrder(result)
#!i=a
for _ in range(10):
print("hi")
#!i=a
#!i=b
print("hello")
def myfun(a):
return a*2
print(myfun(4))
#!i=b
# tree.py
class TreeNode(object):
def __init__(self, x):
def sorted_array_to_bst(nums):
if not nums:
return None
mid_val = len(nums) // 2
\ No newline at end of file
>>>
>>> for _ in range(10):
... print("hi")
\ No newline at end of file
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
>>>
>>>
>>> print("hello")
hello
>>> def myfun(a):
... return a*2
...
\ No newline at end of file
# tree.py
return None
mid_val = len(nums) // 2
node = TreeNode(nums[mid_val])
node.left = sorted_array_to_bst(nums[:mid_val])
node.right = sorted_array_to_bst(nums[mid_val + 1:])
return node
print("hello world asdfasd")
#!o=a
def preOrder(node):
if not node:
return
print(node.val)
preOrder(node.left)
\ No newline at end of file
import os.path
import shutil
from snipper import snip_dir
def setup(source, dest):
if os.path.isdir(dest):
shutil.rmtree(dest)
os.mkdir(dest)
os.mkdir(dest + "/output")
snip_dir(source, dest_dir=dest + "/code", clean_destination_dir=True, output_dir=dest + "/output")
if __name__ == "__main__":
print("File used for setting up sets -- don't run this script unless repository known to work (Tue, 2022)")
if os.path.isdir("student_repo"):
shutil.rmtree("student_repo")
from snipper import snip_dir
# if not os.path.isdir("student_correct_output"):
# os.mkdir("student_correct_output")
setup("demo1", "demo1_correct")
def compare(source, dest):
pass
a= 234
# assert False
from unittest import TestCase
import filecmp
class dircmp(filecmp.dircmp):
"""
Compare the content of dir1 and dir2. In contrast with filecmp.dircmp, this
subclass compares the content of files with the same path.
"""
def phase3(self):
"""
Find out differences between common files.
Ensure we are using content comparison with shallow=False.
"""
fcomp = filecmp.cmpfiles(self.left, self.right, self.common_files,
shallow=False)
self.same_files, self.diff_files, self.funny_files = fcomp
import os.path
def is_same(dir1, dir2):
"""
Compare two directory trees content.
Return False if they differ, True is they are the same.
"""
compared = dircmp(dir1, dir2)
if (compared.left_only or compared.right_only or compared.diff_files
or compared.funny_files):
return False
for subdir in compared.common_dirs:
if not is_same(os.path.join(dir1, subdir), os.path.join(dir2, subdir)):
return False
return True
class TestPython(TestCase):
def test_demo1(self):
from setup_test_files import setup
setup("demo1", "demo1_tmp")
import filecmp
report = filecmp.dircmp("demo1_correct", "demo1_tmp")
print("Different", report.report())
self.assertTrue(is_same("demo1_correct", "demo1_tmp"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment