Пример #1
0
    def test_analyze_coverage(self) -> None:
        fake_setup_py = Path("unittest/setup.py")
        fake_venv_path = self.loop.run_until_complete(
            ptr.create_venv("https://pypi.com/s", install_pkgs=False))
        self.assertIsNone(
            ptr._analyze_coverage(fake_venv_path, fake_setup_py, {}, ""))
        self.assertIsNone(
            ptr._analyze_coverage(fake_venv_path, fake_setup_py, {"bla": 69},
                                  ""))

        # Test with simple py_modules
        self.assertEqual(
            ptr._analyze_coverage(
                fake_venv_path,
                fake_setup_py,
                ptr_tests_fixtures.FAKE_REQ_COVERAGE,
                ptr_tests_fixtures.SAMPLE_REPORT_OUTPUT,
            ),
            ptr_tests_fixtures.EXPECTED_COVERAGE_FAIL_RESULT,
        )

        # Test with venv installed modules
        self.assertEqual(
            ptr._analyze_coverage(
                fake_venv_path,
                fake_setup_py,
                ptr_tests_fixtures.FAKE_TG_REQ_COVERAGE,
                ptr_tests_fixtures.SAMPLE_TG_REPORT_OUTPUT,
            ),
            ptr_tests_fixtures.EXPECTED_PTR_COVERAGE_FAIL_RESULT,
        )

        rmtree(fake_venv_path)
Пример #2
0
 def test_analyze_coverage_errors(self, mock_path: Mock) -> None:
     mock_path.return_value = None
     fake_path = Path(gettempdir())
     self.assertIsNone(ptr._analyze_coverage(fake_path, fake_path, {}, ""))
     mock_path.return_value = fake_path
     self.assertIsNone(
         ptr._analyze_coverage(fake_path, fake_path, {}, "Fake Cov Report"))
Пример #3
0
    def test_analyze_coverage(self, mock_log: Mock, mock_time: Mock) -> None:
        mock_time.return_value = 0
        fake_setup_py = Path("unittest/setup.py")
        if "VIRTUAL_ENV" in environ:
            fake_venv_path = Path(environ["VIRTUAL_ENV"])
        else:
            fake_venv_path = self.loop.run_until_complete(
                ptr.create_venv("https://pypi.com/s", install_pkgs=False))
        self.assertIsNone(
            ptr._analyze_coverage(fake_venv_path, fake_setup_py, {}, "", {},
                                  0))
        self.assertIsNone(
            ptr._analyze_coverage(fake_venv_path, fake_setup_py, {"bla": 69},
                                  "", {}, 0))

        # Test with simple py_modules
        self.assertEqual(
            ptr._analyze_coverage(
                fake_venv_path,
                fake_setup_py,
                ptr_tests_fixtures.FAKE_REQ_COVERAGE,
                ptr_tests_fixtures.SAMPLE_REPORT_OUTPUT,
                {},
                0,
            ),
            ptr_tests_fixtures.EXPECTED_COVERAGE_FAIL_RESULT,
        )

        # Test with venv installed modules
        cov_report = (ptr_tests_fixtures.SAMPLE_WIN_TG_REPORT_OUTPUT
                      if ptr.WINDOWS else
                      ptr_tests_fixtures.SAMPLE_NIX_TG_REPORT_OUTPUT)
        self.assertEqual(
            ptr._analyze_coverage(
                fake_venv_path,
                fake_setup_py,
                ptr_tests_fixtures.FAKE_TG_REQ_COVERAGE,
                cov_report,
                {},
                0,
            ),
            ptr_tests_fixtures.EXPECTED_PTR_COVERAGE_FAIL_RESULT,
        )
        # Test we error on non existent files with coverage requirements
        self.assertEqual(
            ptr._analyze_coverage(fake_venv_path, fake_setup_py,
                                  {"fake_file.py": 48}, cov_report, {}, 0),
            ptr_tests_fixtures.EXPECTED_PTR_COVERAGE_MISSING_FILE_RESULT,
        )
        self.assertTrue(mock_log.called)
        # Dont delete the VIRTUAL_ENV carrying the test if we didn't make it
        if "VIRTUAL_ENV" not in environ:
            rmtree(fake_venv_path)
Пример #4
0
    def test_analyze_coverage(self) -> None:
        fake_setup_py = Path("unittest/setup.py")
        if "VIRTUAL_ENV" in environ:
            fake_venv_path = Path(environ["VIRTUAL_ENV"])
        else:
            fake_venv_path = self.loop.run_until_complete(
                ptr.create_venv("https://pypi.com/s", install_pkgs=False))
        self.assertIsNone(
            ptr._analyze_coverage(fake_venv_path, fake_setup_py, {}, "", {}))
        self.assertIsNone(
            ptr._analyze_coverage(fake_venv_path, fake_setup_py, {"bla": 69},
                                  "", {}))

        # Test with simple py_modules
        self.assertEqual(
            ptr._analyze_coverage(
                fake_venv_path,
                fake_setup_py,
                ptr_tests_fixtures.FAKE_REQ_COVERAGE,
                ptr_tests_fixtures.SAMPLE_REPORT_OUTPUT,
                {},
            ),
            ptr_tests_fixtures.EXPECTED_COVERAGE_FAIL_RESULT,
        )

        # Test with venv installed modules
        cov_report = (ptr_tests_fixtures.SAMPLE_WIN_TG_REPORT_OUTPUT
                      if ptr.WINDOWS else
                      ptr_tests_fixtures.SAMPLE_NIX_TG_REPORT_OUTPUT)
        self.assertEqual(
            ptr._analyze_coverage(
                fake_venv_path,
                fake_setup_py,
                ptr_tests_fixtures.FAKE_TG_REQ_COVERAGE,
                cov_report,
                {},
            ),
            ptr_tests_fixtures.EXPECTED_PTR_COVERAGE_FAIL_RESULT,
        )

        # Dont delete the VIRTUAL_ENV carrying the test if we didn't make it
        if "VIRTUAL_ENV" not in environ:
            rmtree(fake_venv_path)