Skip to content

Commit

Permalink
Issue #49: AttributeError: 'NoneType' object has no attribute 'values…
Browse files Browse the repository at this point in the history
…' in sourcecode_page.py (added python-dateutil for tests).
  • Loading branch information
Nekmo committed Oct 15, 2023
1 parent d24f75e commit 122b936
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12-dev"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand All @@ -19,7 +19,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox-gh-actions tomlkit
pip install tox-gh-actions tomlkit python-dateutil
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
pip install 'setuptools>=66.1.0'
- name: Test with coverage
Expand Down
57 changes: 38 additions & 19 deletions tests/sources/test_sourcecode_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,45 @@ def test_get_cache_data(
self, mock_get_github_readme: MagicMock, mock_datetime: MagicMock
):
"""Test the get_cache_data method."""
mock_get_github_readme.return_value = "pip install repo"
mock_package = Mock()
mock_package.name = "repo"
mock_package.pypi.package = {
"info": {"project_urls": {"Source": "https://github.com/owner/repo"}}
}
cache_dict = SourcecodePage(mock_package).get_cache_data()
self.assertEqual(
{
"package_name": "repo",
"updated_at": mock_datetime.datetime.now.return_value.isoformat.return_value,
"source": "github",
"sourcecode": {
"package_in_readme": True,
"readme_content": mock_get_github_readme.return_value,
with self.subTest("Test package in readme"):
mock_get_github_readme.return_value = "pip install repo"
mock_package = Mock()
mock_package.name = "repo"
mock_package.pypi.package = {
"info": {"project_urls": {"Source": "https://github.com/owner/repo"}}
}
cache_dict = SourcecodePage(mock_package).get_cache_data()
self.assertEqual(
{
"package_name": "repo",
"updated_at": mock_datetime.datetime.now.return_value.isoformat.return_value,
"source": "github",
"sourcecode": {
"package_in_readme": True,
"readme_content": mock_get_github_readme.return_value,
},
},
},
cache_dict,
)
mock_get_github_readme.assert_called_once_with("owner", "repo")
cache_dict,
)
mock_get_github_readme.assert_called_once_with("owner", "repo")
with self.subTest("Test missing project urls in package"):
mock_package = Mock()
mock_package.name = "repo"
mock_package.pypi.package = {"info": {"project_urls": None}}
cache_dict = SourcecodePage(mock_package).get_cache_data()
self.assertEqual(
{
"package_name": "repo",
"updated_at": mock_datetime.datetime.now.return_value.isoformat.return_value,
"source": "github",
"sourcecode": {
"package_in_readme": None,
"readme_content": "",
},
},
cache_dict,
)
mock_get_github_readme.assert_called_once_with("owner", "repo")

@patch(
"pip_rating.sources.sourcecode_page.SourceBase.is_cache_expired",
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ python =
# passenv=*
deps =
tomlkit
python-dateutil
-rrequirements-dev.txt

commands=
Expand Down

0 comments on commit 122b936

Please sign in to comment.