Exemplo n.º 1
0
 def test_not(self):
     Pipeline(
         Run(["ls"]),
         # Essentially, assert not contains, which should fail.
         Not(AssertStdoutContains(strings=["imaginary.file"])),
     )()
     with self.assertRaises(AssertionError):
         Pipeline(Run(["echo", "hello world"]),
                  Not(AssertStdoutContains(strings=["hello"])))()
Exemplo n.º 2
0
 def test_or(self):
     Pipeline(
         Run(["echo", "hello world"]),
         Or(AssertStdoutContains(["goodbye"]),
            AssertStdoutContains(["hello"])),
     )()
     with self.assertRaises(AssertionError):
         Pipeline(
             Run(["echo", "hello world"]),
             Or(AssertStdoutContains(["goodbye"]),
                AssertStderrContains(["goodbye"])),
         )()
Exemplo n.º 3
0
 def test_input():
     Pipeline(
         Run(["cat", "README.md"]),
         AssertExitSuccess(),
         Run(["grep", "Setup"], input=lambda r: r.stdout),
         AssertStdoutMatches("## Setup"),
     )()
     Pipeline(
         Run(["grep", "hello", "-"],
             input="hello world\nhear me test things!"),
         AssertStdoutMatches("hello world"),
     )()
     Pipeline(Run(["python", "-c", "x = input(); print(x)"], input="5"),
              AssertStdoutMatches("5"))()
Exemplo n.º 4
0
 def test_iteration(self):
     pipeline = Pipeline(
         Run(["ls"]), AssertExitSuccess(), AssertValgrindSuccess(), WriteOutputs("temp"),
     )
     [self.assertTrue(callable(callback)) for callback in pipeline]
     self.assertIsInstance(pipeline[1], AssertExitSuccess)
     self.assertEqual(len(pipeline), 4)
Exemplo n.º 5
0
 def test_partial_credit(self):
     pipelines = map(lambda t: Pipeline(Run([t]), AssertExitSuccess()),
                     ["ls", "void"])
     with self.assertLogs() as logs:
         results = PartialCredit(pipelines, 10)()
     self.assertIn("ERROR:root:", logs.output[0])
     self.assertEqual(results.score, 5)
Exemplo n.º 6
0
 def test_successful_no_output():
     Pipeline(
         Run([PYTHON, "-m", "grade", "run", "-p", "test_mixins.py"]),
         AssertExitSuccess(),
         AssertStdoutMatches(""),
         AssertStderrMatches(""),
     )()
Exemplo n.º 7
0
 def test_value_list_all_fail(self):
     pipelines = map(lambda t: Pipeline(Run(["ls"]), AssertExitFailure()),
                     range(5))
     values = [10, 1]
     logging.disable(logging.CRITICAL)
     results = PartialCredit(pipelines, values)()
     logging.disable(logging.NOTSET)
     self.assertEqual(results.score, 0)
Exemplo n.º 8
0
 def test_value_list_some_fail(self):
     pipelines = map(lambda t: Pipeline(Run([t]), AssertExitSuccess()),
                     ["ls", "void", "ls", "void"])
     values = [10, 1]  # 10, 1
     logging.disable(logging.CRITICAL)
     results = PartialCredit(pipelines, values)()
     logging.disable(logging.NOTSET)
     self.assertEqual(results.score, 20)
Exemplo n.º 9
0
 def test_no_credit(self):
     pipelines = map(lambda t: Pipeline(Run(["ls"]), AssertExitFailure()),
                     range(10))
     with self.assertLogs() as logs:
         results = PartialCredit(pipelines, 10)()
     self.assertEqual(10, len(logs.output))
     self.assertIn("ERROR:root:['ls'] should have exited unsuccessfully.",
                   logs.output)
     self.assertEqual(results.score, 0)
Exemplo n.º 10
0
    def test_executable(self):
        """ Checking executable files with a Pipeline.

        Pipelines are designed around testing executable files.
        They are comprised of "layers" which pass CompletedProcess objects to
        each other. You can stack layers however you'd like, but they must start
        with a call to Run(), which generates the initial CompletedProcess.
        """
        Pipeline(Run(["ls"]), AssertExitSuccess(), AssertValgrindSuccess())()
Exemplo n.º 11
0
 def test_json_output(self):
     Pipeline(
         Run([PYTHON, "-m", "grade", "run", "-p", "test_mixins.py"]),
         Run([PYTHON, "-m", "grade", "report", "--format", "json"]),
         AssertExitSuccess(),
         AssertStdoutContains(["tests"]),
         Lambda(lambda results: self.assertGreater(
             len(json.loads(results.stdout)["tests"]), 3)),
     )()
Exemplo n.º 12
0
    def test_collecting_runtimes(self):
        """ CompletedProcess objects all know their duration.

        Duration can be used to allocate points based on speed, or add to a
        leaderboard!
        """
        # To setup a leaderboard, you have to at least set it's name.
        self.leaderboardTitle = "Runtime"
        # (Desc)ending or (asc)ending order (desc default)
        self.leaderboardOrder = "desc"

        self.weight = 10

        results = Pipeline(Run(["echo", "hello world"]), AssertExitSuccess())()
        # Here we set the leaderboard score as the duration.
        self.leaderboardScore = results.duration

        if results.duration < 1_000:
            self.score = 10
        elif results.duration < 10_000:
            self.score = 5
Exemplo n.º 13
0
 def pipeline(testcase):
     """ Create a pipeline for the given testcase. """
     return Pipeline(Run(["echo", testcase]), AssertExitSuccess())
Exemplo n.º 14
0
 def test_fail_multiple(self):
     with self.assertRaises(AssertionError):
         tests = map(lambda t: Pipeline(Run(["ls"]), AssertExitFailure()), range(10))
         [test() for test in tests]
Exemplo n.º 15
0
 def test_full_credit(self):
     pipelines = map(lambda t: Pipeline(Run(["ls"])), range(10))
     results = PartialCredit(pipelines, 10)()
     self.assertEqual(results.score, 10)
Exemplo n.º 16
0
 def test_no_arguments():
     Pipeline(
         Run([PYTHON, "-m", "grade"]),
         AssertExitSuccess(),
     )
Exemplo n.º 17
0
 def test_value_list_credit(self):
     pipelines = map(lambda t: Pipeline(Run(["ls"])), range(2))
     values = [10, 1]
     results = PartialCredit(pipelines, values)()
     self.assertEqual(results.score, 11)
Exemplo n.º 18
0
 def test_faster():
     Pipeline(
         Run(["echo", "hello world"]),
         AssertFaster(10),
         Not(AssertFaster(0)),
     )()
Exemplo n.º 19
0
 def test_score_rotation(self):
     pipelines = map(lambda t: Pipeline(Run(["ls"])), range(5))
     values = [100, 10, 1]  # 100, 10
     results = PartialCredit(pipelines, values)()
     self.assertEqual(results.score, 221)
Exemplo n.º 20
0
 def test_assert_exit_status():
     Pipeline(
         Run(["echo", "hello world"]),
         AssertExitStatus(0),
         Not(AssertExitStatus(1)),
     )()
Exemplo n.º 21
0
 def test_fails(self):
     with self.assertRaises(AssertionError):
         Pipeline(Run(["ls"]), AssertExitFailure())()
Exemplo n.º 22
0
 def test_pass_multiple():
     tests = map(lambda t: Pipeline(Run(["ls"]), AssertExitSuccess()), range(10))
     [test() for test in tests]
Exemplo n.º 23
0
 def test_passes():
     Pipeline(Run(["ls"]), AssertExitSuccess())