# from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem
# from unitgrade.unitgrade_helpers import evaluate_report_student

from src.unitgrade2.unitgrade2 import UTestCase, cache
# from unitgrade2.unitgrade2 import cache
from src.unitgrade2.unitgrade2 import methodsWithDecorator, hide



import random
from cs101courseware_example.homework1 import my_sum

class GeneratorQuestion(UTestCase):
    def genTest(self, n):
        seq = [random.randint(1, 100000) for _ in range(n)]
        return my_sum(seq)



class ListQuestion(UTestCase):
    """ Docstring at top """

    @classmethod
    def setUpClass(cls) -> None:
        z = 23424
        # print(" calling setUpClass()...")
        pass

    def test_integers(self):
        """ aa test_integers-short """
        self.__class__.a = "fun1"
        from cs101courseware_example.homework1 import reverse_list
        # self.a = self.a + 2
        self.assertEqual(reverse_list([1, 2, 3]), [3, 2, 1])
        self.assertEqualC(reverse_list([1,2,3]))
        self.assertEqualC(reverse_list(["23", "asdfsadf"]))
        return dict(title="test integers...")

    @cache
    def my_funny_computation(self, a):
        return a*2

    def test_strings(self):
        """ xxxxtest_integers-short """
        # import time
        # time.sleep(1.1)
        a = self.my_funny_computation(2)

        from cs101courseware_example.homework1 import reverse_list
        l =  ["hello", "world", "summer", "dog"]
        self.assertEqual(reverse_list(l), list(reversed(l)))

    def test_more_integerrs(self):
        """ ccc test_integers-short """
        self.assertEqual(2,2)

from src.unitgrade2.unitgrade2 import Report

class Report1(Report):
    title = "CS 202 Report 1"
    questions = [
        (GeneratorQuestion, 10),
        (ListQuestion, 5)
                ]

    import cs202courseware
    pack_imports = [cs202courseware]  # Include this file in .token file
    a = 234

def docker_test_uploads(student_id, student_file, source_repo_report_class, student_repo_report_class):
    # The student file contains a list of all uploaded files.
    source_base_dir = "" # Location of all source files for project. Must be the 'real' version required to get project to run.
    # Or should it be? Why?
    # Need a directory where we are going to work. must be the image location.
    docker_image_location = ""
    # Make a tmp location in docker directory.
    docker_tmp_file_system = docker_image_location + "/tmp"
    # This is where the docker file system is going to run.
    import pickle
    with open(student_file, 'rb') as f:
        upload = pickle.load(f)

    # report-location is given in the student repo (within their fs relative to root).

    # Now we have the upload.

    pass


if __name__ == "__main__":
    """
    Capture output in TestCase
    
    HTML test runner:
    https://awesomeopensource.com/project/oldani/HtmlTestRunner
    
    """
    import inspect
    ls = list(methodsWithDecorator(GeneratorQuestion, hide))
    for f in ls:
        print(inspect.getsourcelines(f) ) # How to get all hidden questions.

    from src.unitgrade2 import evaluate_report_student

    evaluate_report_student( Report1() )


    # unittest.main(verbosity=2)
    # deploy the report
    from unitgrade_private2.hidden_create_files import setup_grade_file_report
    setup_grade_file_report(Report1, minify=False, obfuscate=False, execute=False)