Пример #1
0
    def test_Log_getItem(self):
        entry1 = LogEntry(event_type=EventType.AUTH,
                          results=[],
                          question=None,
                          success=True,
                          error=None)

        entry1.flush_to_file(_OTTER_LOG_FILENAME)

        log = Log.from_file(_OTTER_LOG_FILENAME)

        self.assertEqual(log.__getitem__(0).event_type, entry1.event_type)
Пример #2
0
    def test_shelve(self):
        # tests shelve() and unshelve() which call shelve_environment()

        def square(x):
            return x**2

        import calendar 

        env = {"num": 5, "func": square, "model": LinearRegression(), "module": sys, "ignored_func": calendar.setfirstweekday}

     
        entry = LogEntry(
            event_type=EventType.AUTH,
            results=[],
            question=None, 
            success=True, 
            error=None
        )
 

        entry.shelve(env, delete=True, filename = _OTTER_LOG_FILENAME, ignore_modules=['calendar'])
        self.assertTrue(entry.shelf)
        self.assertEqual(entry.unshelved, ["module", "ignored_func"])

        entry.flush_to_file(_OTTER_LOG_FILENAME) 

        from math import factorial

        log = Log.from_file(_OTTER_LOG_FILENAME)
        env = entry.unshelve()
        self.assertEqual([*env], ["num", "func", "model"])

        env_with_factorial = entry.unshelve(dict(factorial = factorial ))
        self.assertTrue("factorial" in env_with_factorial["func"].__globals__)
        self.assertTrue(factorial is env_with_factorial["func"].__globals__["factorial"])
Пример #3
0
    def test_nb_log(self, mock_log):
        """
        Checks existence of log when running nb
        """

        mock_log.return_value = LogEntry(EventType.CHECK)
        grader = Notebook(test_dir=TEST_FILES_PATH + "tests")
        output = grader.check_all()

        self.assertTrue(os.path.isfile(_OTTER_LOG_FILENAME))
Пример #4
0
    def test_Log_iter(self):
        #log = Log.from_file(_OTTER_LOG_FILENAME, ascending = True)
        #list of entries
        #logIter = log.iter()

        entry1 = LogEntry(event_type=EventType.CHECK,
                          results=[],
                          question="q1",
                          success=True,
                          error=None)

        entry2 = LogEntry(event_type=EventType.CHECK,
                          results=[],
                          question="q1",
                          success=True,
                          error=None)

        entry3 = LogEntry(event_type=EventType.CHECK,
                          results=[],
                          question="q2",
                          success=True,
                          error=None)

        entry1.flush_to_file(_OTTER_LOG_FILENAME)
        entry2.flush_to_file(_OTTER_LOG_FILENAME)
        entry3.flush_to_file(_OTTER_LOG_FILENAME)

        log = Log.from_file(_OTTER_LOG_FILENAME)

        logIter = log.question_iterator()  #most recent entries / question
        self.assertEqual(logIter.questions, ["q1", "q2"])

        nextLogEntry = next(logIter)

        self.assertEqual(nextLogEntry.question, entry2.question)

        nextLogEntry = next(logIter)

        self.assertEqual(nextLogEntry.question, entry3.question)