How to use pypistats - 10 common examples

To help you get started, we’ve selected a few pypistats 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 hugovk / pypistats / tests / test_pypistats.py View on Github external
# Arrange
        package = "pip"
        mocked_url = "https://pypistats.org/api/packages/pip/overall"
        mocked_response = SAMPLE_RESPONSE_OVERALL
        expected_output = """
|    category     | downloads |
|-----------------|----------:|
| without_mirrors | 2,297,591 |

Date range: 2018-11-02 - 2018-11-02
"""

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            output = pypistats.overall(package, mirrors=False, start_date="2018-11-02")

        # Assert
        self.assertEqual(output.strip(), expected_output.strip())
github hugovk / pypistats / tests / test_pypistats_cache.py View on Github external
"package": "pip",
          "type": "overall_downloads"
        }"""
        expected_output = """
|    category     | downloads |
|-----------------|----------:|
| without_mirrors | 2,295,765 |
"""

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            # First time to save to cache
            pypistats.overall(package)
            # Second time to read from cache
            output = pypistats.overall(package)

        # Assert
        self.assertEqual(output.strip(), expected_output.strip())
github hugovk / pypistats / tests / test_pypistats.py View on Github external
# Arrange
        package = "pip"
        mocked_url = "https://pypistats.org/api/packages/pip/overall"
        mocked_response = SAMPLE_RESPONSE_OVERALL
        expected_output = """
|    category     | downloads |
|-----------------|----------:|
| without_mirrors | 2,295,765 |

Date range: 2018-11-01 - 2018-11-01
"""

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            output = pypistats.overall(package, mirrors=False, end_date="2018-11-01")

        # Assert
        self.assertEqual(output.strip(), expected_output.strip())
github hugovk / pypistats / tests / test_pypistats_cache.py View on Github external
{"category": "without_mirrors", "date": "2018-11-01", "downloads": 2295765}
          ],
          "package": "pip",
          "type": "overall_downloads"
        }"""
        expected_output = """
|    category     | downloads |
|-----------------|----------:|
| without_mirrors | 2,295,765 |
"""

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            # First time to save to cache
            pypistats.overall(package)
            # Second time to read from cache
            output = pypistats.overall(package)

        # Assert
        self.assertEqual(output.strip(), expected_output.strip())
github hugovk / pypistats / tests / test_pypistats.py View on Github external
def test_valid_json(self):
        # Arrange
        package = "pip"
        mocked_url = "https://pypistats.org/api/packages/pip/recent?&period=day"
        mocked_response = """
        {"data": {"last_day": 1956060}, "package": "pip", "type": "recent_downloads"}
        """

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            output = pypistats.recent(package, period="day", format="json")

        # Assert
        # Should not raise any errors eg. TypeError
        json.loads(output)
        self.assertEqual(json.loads(output), json.loads(mocked_response))
github hugovk / pypistats / tests / test_pypistats.py View on Github external
mocked_url = "https://pypistats.org/api/packages/pip/recent"
        mocked_response = """{
            "data":
                {"last_day": 2295765, "last_month": 67759913, "last_week": 15706750},
            "package": "pip", "type": "recent_downloads"
        }"""
        expected_output = """
| last_day  | last_month | last_week  |
|----------:|-----------:|-----------:|
| 2,295,765 | 67,759,913 | 15,706,750 |
"""

        # Act
        with requests_mock.Mocker() as m:
            m.get(mocked_url, text=mocked_response)
            output = pypistats.recent(package)

        # Assert
        self.assertEqual(output.strip(), expected_output.strip())
github hugovk / pypistats / tests / test_pypistats.py View on Github external
def test__paramify_string(self):
        # Arrange
        period = "day"

        # Act
        param = pypistats._paramify("period", period)

        # Assert
        self.assertEqual(param, "&period=day")
github hugovk / pypistats / tests / test_pypistats.py View on Github external
def test__paramify_float(self):
        # Arrange
        version = 3.7

        # Act
        param = pypistats._paramify("version", version)

        # Assert
        self.assertEqual(param, "&version=3.7")
github hugovk / pypistats / tests / test_pypistats.py View on Github external
def test__paramify_none(self):
        # Arrange
        period = None

        # Act
        param = pypistats._paramify("period", period)

        # Assert
        self.assertEqual(param, "")
github hugovk / pypistats / tests / test_pypistats.py View on Github external
def test__paramify_bool(self):
        # Arrange
        mirrors = True

        # Act
        param = pypistats._paramify("mirrors", mirrors)

        # Assert
        self.assertEqual(param, "&mirrors=true")