How to use ptr - 10 common examples

To help you get started, we’ve selected a few ptr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebookincubator / ptr / ptr_tests.py View on Github external
def test_config(self) -> None:
        expected_pypi_url = "https://pypi.org/simple/"
        dc = ptr._config_default()
        self.assertEqual(dc["ptr"]["pypi_url"], expected_pypi_url)
        dc["ptr"]["cpu_count"] = "10"

        td = Path(__file__).parent
        sc = ptr._config_read(str(td), "ptrconfig.sample")
        self.assertEqual(sc["ptr"].get("pypi_url", ""), expected_pypi_url)
        self.assertEqual(len(sc["ptr"].get("venv_pkgs", "").split()), 8)
github facebookincubator / ptr / ptr_tests.py View on Github external
def test_config(self) -> None:
        expected_pypi_url = "https://pypi.org/simple/"
        dc = ptr._config_default()
        self.assertEqual(dc["ptr"]["pypi_url"], expected_pypi_url)
        dc["ptr"]["cpu_count"] = "10"

        td = Path(__file__).parent
        sc = ptr._config_read(str(td), "ptrconfig.sample")
        self.assertEqual(sc["ptr"].get("pypi_url", ""), expected_pypi_url)
        self.assertEqual(len(sc["ptr"].get("venv_pkgs", "").split()), 8)
github facebookincubator / ptr / ptr_tests.py View on Github external
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, {}, "", {}, 0))
        mock_path.return_value = fake_path
        self.assertIsNone(
            ptr._analyze_coverage(fake_path, fake_path, {}, "Fake Cov Report", {}, 0)
        )
github facebookincubator / ptr / ptr_tests.py View on Github external
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,
github facebookincubator / ptr / ptr_tests.py View on Github external
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,
        )
github facebookincubator / ptr / ptr_tests.py View on Github external
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)
github facebookincubator / ptr / ptr_tests.py View on Github external
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
github facebookincubator / ptr / ptr_tests.py View on Github external
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, {}, "", {}, 0))
        mock_path.return_value = fake_path
        self.assertIsNone(
            ptr._analyze_coverage(fake_path, fake_path, {}, "Fake Cov Report", {}, 0)
        )
github facebookincubator / ptr / ptr_tests.py View on Github external
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
        )
github facebookincubator / ptr / ptr_tests.py View on Github external
def test_mac_osx_slash_private(self) -> None:
        macosx = ptr.MACOSX
        non_private_path_str = "/var/tmp"
        private_path_str = f"/private{non_private_path_str}"
        site_packages_path = Path("/var/tmp/venv/lib/site-packages/")
        try:
            ptr.MACOSX = False
            self.assertEqual(
                Path(private_path_str),
                ptr._max_osx_private_handle(private_path_str, site_packages_path),
            )

            ptr.MACOSX = True
            self.assertEqual(
                Path(non_private_path_str),
                ptr._max_osx_private_handle(private_path_str, site_packages_path),
            )

            site_packages_path = Path("/private/var/tmp/venv/lib/site-packages/")
            self.assertEqual(
                Path(private_path_str),
                ptr._max_osx_private_handle(private_path_str, site_packages_path),
            )
        finally:
            # Ensure we also restore if we're MACOSX or not
            ptr.MACOSX = macosx