示例#1
0
 def test_screenshot_truncated(self, p):
     s = Screenshots()
     s.shots_path = os.path.join("tests", "files",
                                 "sample_analysis_storage", "shots")
     s.set_options({})
     p.open.return_value.save.side_effect = IOError(
         "image file is truncated (42 bytes not processed)")
     assert s.run() == []
示例#2
0
 def test_screenshot_truncated(self, p):
     s = Screenshots()
     s.shots_path = os.path.join(
         "tests", "files", "sample_analysis_storage", "shots"
     )
     s.set_options({})
     p.open.return_value.save.side_effect = IOError(
         "image file is truncated (42 bytes not processed)"
     )
     assert s.run() == []
示例#3
0
 def test_ignore_notesseract(self, p, q):
     s = Screenshots()
     s.shots_path = os.path.join("tests", "files",
                                 "sample_analysis_storage", "shots")
     s.set_options({
         "tesseract": "no",
     })
     assert len(s.run()) == 1
     p.error.assert_not_called()
     p.warning.assert_not_called()
     q.check_output.assert_not_called()
     shotpath = os.path.join("tests", "files", "sample_analysis_storage",
                             "shots", "0001_small.jpg")
     assert os.path.exists(shotpath)
     os.unlink(shotpath)
示例#4
0
 def test_ignore_notesseract(self, p, q):
     s = Screenshots()
     s.shots_path = os.path.join(
         "tests", "files", "sample_analysis_storage", "shots"
     )
     s.set_options({
         "tesseract": "no",
     })
     assert len(s.run()) == 1
     p.error.assert_not_called()
     p.warning.assert_not_called()
     q.check_output.assert_not_called()
     shotpath = os.path.join(
         "tests", "files", "sample_analysis_storage",
         "shots", "0001_small.jpg"
     )
     assert os.path.exists(shotpath)
     os.unlink(shotpath)
示例#5
0
 def test_screenshots(self, p):
     s = Screenshots()
     s.shots_path = os.path.join("tests", "files",
                                 "sample_analysis_storage", "shots")
     s.set_options({
         "tesseract": __file__,
     })
     p.check_output.return_value = "foobar"
     assert s.run() == [{
         "path": os.path.join(s.shots_path, "0001.jpg"),
         "ocr": "foobar",
     }]
     p.check_output.assert_called_once_with(
         [__file__,
          os.path.join(s.shots_path, "0001.jpg"), "stdout"])
     shotpath = os.path.join("tests", "files", "sample_analysis_storage",
                             "shots", "0001_small.jpg")
     assert os.path.exists(shotpath)
     os.unlink(shotpath)
示例#6
0
    def test_screenshot_tesseract(self, p):
        s = Screenshots()
        # Use an empty directory so no actual screenshot analysis is done.
        s.shots_path = tempfile.mkdtemp()
        s.set_options({
            "tesseract": None,
        })
        assert s.run() == []
        p.error.assert_not_called()

        s.set_options({
            "tesseract": "no",
        })
        assert s.run() == []
        p.error.assert_not_called()

        s.set_options({
            "tesseract": "thispathdoesnotexist",
        })
        assert s.run() == []
        p.error.assert_called_once()
示例#7
0
 def test_screenshots(self, p):
     s = Screenshots()
     s.shots_path = os.path.join(
         "tests", "files", "sample_analysis_storage", "shots"
     )
     s.set_options({
         "tesseract": __file__,
     })
     p.check_output.return_value = "foobar"
     assert s.run() == [{
         "path": os.path.join(s.shots_path, "0001.jpg"),
         "ocr": "foobar",
     }]
     p.check_output.assert_called_once_with([
         __file__, os.path.join(s.shots_path, "0001.jpg"), "stdout"
     ])
     shotpath = os.path.join(
         "tests", "files", "sample_analysis_storage",
         "shots", "0001_small.jpg"
     )
     assert os.path.exists(shotpath)
     os.unlink(shotpath)