Compare commits
3 commits
main
...
fix-mbid-t
Author | SHA1 | Date | |
---|---|---|---|
|
69cc18bcbd | ||
|
8d784d6417 | ||
|
58fa3094d8 |
|
@ -11,6 +11,7 @@ charset = utf-8
|
||||||
[*.py]
|
[*.py]
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
indent_style = space
|
indent_style = space
|
||||||
|
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
# Two-space indentation
|
# Two-space indentation
|
||||||
|
|
7
.github/ISSUE_TEMPLATE.md
vendored
7
.github/ISSUE_TEMPLATE.md
vendored
|
@ -12,11 +12,8 @@
|
||||||
|
|
||||||
Please include **code** that reproduces the issue.
|
Please include **code** that reproduces the issue.
|
||||||
|
|
||||||
The [best reproductions](https://stackoverflow.com/help/minimal-reproducible-example)
|
The [best reproductions](https://stackoverflow.com/help/minimal-reproducible-example) are [self-contained scripts](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) with minimal dependencies.
|
||||||
are
|
|
||||||
[self-contained scripts](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)
|
|
||||||
with minimal dependencies.
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# code goes here
|
code goes here
|
||||||
```
|
```
|
||||||
|
|
17
.github/labels.yml
vendored
17
.github/labels.yml
vendored
|
@ -91,21 +91,12 @@
|
||||||
- color: b60205
|
- color: b60205
|
||||||
description: Removal of a feature, usually done in major releases
|
description: Removal of a feature, usually done in major releases
|
||||||
name: removal
|
name: removal
|
||||||
|
- color: 2d18b2
|
||||||
|
description: "To automatically merge PRs that are ready"
|
||||||
|
name: automerge
|
||||||
- color: 0366d6
|
- color: 0366d6
|
||||||
description: "For dependencies"
|
description: "For dependencies"
|
||||||
name: dependencies
|
name: dependencies
|
||||||
- color: 0052cc
|
|
||||||
description: "Documentation"
|
|
||||||
name: docs
|
|
||||||
- color: f4660e
|
|
||||||
description: ""
|
|
||||||
name: Hacktoberfest
|
|
||||||
- color: f4660e
|
|
||||||
description: "To credit accepted Hacktoberfest PRs"
|
|
||||||
name: hacktoberfest-accepted
|
|
||||||
- color: d65e88
|
|
||||||
description: "Deploy and release"
|
|
||||||
name: release
|
|
||||||
- color: fef2c0
|
- color: fef2c0
|
||||||
description: "Unit tests, linting, CI, etc."
|
description: ""
|
||||||
name: test
|
name: test
|
||||||
|
|
28
.github/release-drafter.yml
vendored
28
.github/release-drafter.yml
vendored
|
@ -1,5 +1,5 @@
|
||||||
name-template: "$RESOLVED_VERSION"
|
name-template: "$NEXT_PATCH_VERSION"
|
||||||
tag-template: "$RESOLVED_VERSION"
|
tag-template: "$NEXT_PATCH_VERSION"
|
||||||
|
|
||||||
categories:
|
categories:
|
||||||
- title: "Added"
|
- title: "Added"
|
||||||
|
@ -22,27 +22,7 @@ categories:
|
||||||
exclude-labels:
|
exclude-labels:
|
||||||
- "changelog: skip"
|
- "changelog: skip"
|
||||||
|
|
||||||
autolabeler:
|
|
||||||
- label: "changelog: skip"
|
|
||||||
branch:
|
|
||||||
- "/pre-commit-ci-update-config/"
|
|
||||||
|
|
||||||
template: |
|
template: |
|
||||||
|
## Changes
|
||||||
|
|
||||||
$CHANGES
|
$CHANGES
|
||||||
|
|
||||||
version-resolver:
|
|
||||||
major:
|
|
||||||
labels:
|
|
||||||
- "changelog: Removed"
|
|
||||||
minor:
|
|
||||||
labels:
|
|
||||||
- "changelog: Added"
|
|
||||||
- "changelog: Changed"
|
|
||||||
- "changelog: Deprecated"
|
|
||||||
- "enhancement"
|
|
||||||
|
|
||||||
patch:
|
|
||||||
labels:
|
|
||||||
- "changelog: Fixed"
|
|
||||||
- "bug"
|
|
||||||
default: minor
|
|
||||||
|
|
13
.github/renovate.json
vendored
13
.github/renovate.json
vendored
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": ["config:base"],
|
|
||||||
"labels": ["changelog: skip", "dependencies"],
|
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"groupName": "github-actions",
|
|
||||||
"matchManagers": ["github-actions"],
|
|
||||||
"separateMajorMinor": "false"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"schedule": ["on the first day of the month"]
|
|
||||||
}
|
|
75
.github/workflows/deploy.yml
vendored
75
.github/workflows/deploy.yml
vendored
|
@ -1,75 +0,0 @@
|
||||||
name: Deploy
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
tags: ["*"]
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
release:
|
|
||||||
types:
|
|
||||||
- published
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
# Always build & lint package.
|
|
||||||
build-package:
|
|
||||||
name: Build & verify package
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- uses: hynek/build-and-inspect-python-package@v2
|
|
||||||
|
|
||||||
# Upload to Test PyPI on every commit on main.
|
|
||||||
release-test-pypi:
|
|
||||||
name: Publish in-dev package to test.pypi.org
|
|
||||||
if: |
|
|
||||||
github.repository_owner == 'pylast'
|
|
||||||
&& github.event_name == 'push'
|
|
||||||
&& github.ref == 'refs/heads/main'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build-package
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download packages built by build-and-inspect-python-package
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: Packages
|
|
||||||
path: dist
|
|
||||||
|
|
||||||
- name: Upload package to Test PyPI
|
|
||||||
uses: pypa/gh-action-pypi-publish@release/v1
|
|
||||||
with:
|
|
||||||
repository-url: https://test.pypi.org/legacy/
|
|
||||||
|
|
||||||
# Upload to real PyPI on GitHub Releases.
|
|
||||||
release-pypi:
|
|
||||||
name: Publish released package to pypi.org
|
|
||||||
if: |
|
|
||||||
github.repository_owner == 'pylast'
|
|
||||||
&& github.event.action == 'published'
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build-package
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Download packages built by build-and-inspect-python-package
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: Packages
|
|
||||||
path: dist
|
|
||||||
|
|
||||||
- name: Upload package to PyPI
|
|
||||||
uses: pypa/gh-action-pypi-publish@release/v1
|
|
14
.github/workflows/labels.yml
vendored
14
.github/workflows/labels.yml
vendored
|
@ -1,23 +1,15 @@
|
||||||
name: Sync labels
|
name: Sync labels
|
||||||
|
|
||||||
permissions:
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
paths:
|
paths:
|
||||||
- .github/labels.yml
|
- .github/labels.yml
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
sync:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
- uses: micnncim/action-label-syncer@v1
|
- uses: micnncim/action-label-syncer@v1
|
||||||
with:
|
|
||||||
prune: false
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
45
.github/workflows/lint.yml
vendored
45
.github/workflows/lint.yml
vendored
|
@ -1,22 +1,37 @@
|
||||||
name: Lint
|
name: Lint
|
||||||
|
|
||||||
on: [push, pull_request, workflow_dispatch]
|
on: [push, pull_request]
|
||||||
|
|
||||||
env:
|
|
||||||
FORCE_COLOR: 1
|
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK: 1
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-18.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
|
- name: Cache
|
||||||
|
uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
python-version: "3.x"
|
path: |
|
||||||
cache: pip
|
~/.cache/pip
|
||||||
- uses: pre-commit/action@v3.0.1
|
~/.cache/pre-commit
|
||||||
|
key:
|
||||||
|
lint-v2-${{ hashFiles('**/setup.py') }}-${{
|
||||||
|
hashFiles('**/.pre-commit-config.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
lint-v2-
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.8
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install -U pip
|
||||||
|
python -m pip install -U tox
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: tox -e lint
|
||||||
|
env:
|
||||||
|
PRE_COMMIT_COLOR: always
|
||||||
|
|
25
.github/workflows/release-drafter.yml
vendored
25
.github/workflows/release-drafter.yml
vendored
|
@ -4,31 +4,14 @@ on:
|
||||||
push:
|
push:
|
||||||
# branches to consider in the event; optional, defaults to all
|
# branches to consider in the event; optional, defaults to all
|
||||||
branches:
|
branches:
|
||||||
- main
|
- master
|
||||||
# pull_request event is required only for autolabeler
|
|
||||||
pull_request:
|
|
||||||
# Only following types are handled by the action, but one can default to all as well
|
|
||||||
types: [opened, reopened, synchronize]
|
|
||||||
# pull_request_target event is required for autolabeler to support PRs from forks
|
|
||||||
# pull_request_target:
|
|
||||||
# types: [opened, reopened, synchronize]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update_release_draft:
|
update_release_draft:
|
||||||
if: github.repository_owner == 'pylast'
|
if: github.repository == 'pylast/pylast'
|
||||||
permissions:
|
|
||||||
# write permission is required to create a GitHub Release
|
|
||||||
contents: write
|
|
||||||
# write permission is required for autolabeler
|
|
||||||
# otherwise, read permission is required at least
|
|
||||||
pull-requests: write
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# Drafts your next release notes as pull requests are merged into "main"
|
# Drafts your next release notes as pull requests are merged into "master"
|
||||||
- uses: release-drafter/release-drafter@v6
|
- uses: release-drafter/release-drafter@v5
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
22
.github/workflows/require-pr-label.yml
vendored
22
.github/workflows/require-pr-label.yml
vendored
|
@ -1,22 +0,0 @@
|
||||||
name: Require PR label
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, reopened, labeled, unlabeled, synchronize]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
label:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
issues: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: mheap/github-action-required-labels@v5
|
|
||||||
with:
|
|
||||||
mode: minimum
|
|
||||||
count: 1
|
|
||||||
labels:
|
|
||||||
"changelog: Added, changelog: Changed, changelog: Deprecated, changelog:
|
|
||||||
Fixed, changelog: Removed, changelog: Security, changelog: skip"
|
|
54
.github/workflows/test.yml
vendored
54
.github/workflows/test.yml
vendored
|
@ -1,54 +0,0 @@
|
||||||
name: Test
|
|
||||||
|
|
||||||
on: [push, pull_request, workflow_dispatch]
|
|
||||||
|
|
||||||
env:
|
|
||||||
FORCE_COLOR: 1
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
python-version: ["pypy3.10", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
||||||
os: [ubuntu-latest]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: ${{ matrix.python-version }}
|
|
||||||
allow-prereleases: true
|
|
||||||
cache: pip
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install -U pip
|
|
||||||
python -m pip install -U wheel
|
|
||||||
python -m pip install -U tox
|
|
||||||
|
|
||||||
- name: Tox tests
|
|
||||||
run: |
|
|
||||||
tox -e py
|
|
||||||
env:
|
|
||||||
PYLAST_API_KEY: ${{ secrets.PYLAST_API_KEY }}
|
|
||||||
PYLAST_API_SECRET: ${{ secrets.PYLAST_API_SECRET }}
|
|
||||||
PYLAST_PASSWORD_HASH: ${{ secrets.PYLAST_PASSWORD_HASH }}
|
|
||||||
PYLAST_USERNAME: ${{ secrets.PYLAST_USERNAME }}
|
|
||||||
|
|
||||||
- name: Upload coverage
|
|
||||||
uses: codecov/codecov-action@v3.1.5
|
|
||||||
with:
|
|
||||||
flags: ${{ matrix.os }}
|
|
||||||
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
|
|
||||||
|
|
||||||
success:
|
|
||||||
needs: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Test successful
|
|
||||||
steps:
|
|
||||||
- name: Success
|
|
||||||
run: echo Test successful
|
|
10
.mergify.yml
Normal file
10
.mergify.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pull_request_rules:
|
||||||
|
- name: Automatic merge on approval
|
||||||
|
conditions:
|
||||||
|
- label=automerge
|
||||||
|
- status-success=build
|
||||||
|
- status-success=continuous-integration/travis-ci/pr
|
||||||
|
- status-success=continuous-integration/travis-ci/push
|
||||||
|
actions:
|
||||||
|
merge:
|
||||||
|
method: merge
|
|
@ -1,74 +1,42 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: v0.5.0
|
rev: v2.6.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: pyupgrade
|
||||||
args: [--exit-non-zero-on-fix]
|
args: ["--py3-plus"]
|
||||||
|
|
||||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
- repo: https://github.com/psf/black
|
||||||
rev: 24.4.2
|
rev: 19.10b0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
|
args: ["--target-version", "py35"]
|
||||||
|
# override until resolved: https://github.com/psf/black/issues/402
|
||||||
|
files: \.pyi?$
|
||||||
|
types: []
|
||||||
|
|
||||||
- repo: https://github.com/asottile/blacken-docs
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: 1.18.0
|
rev: 3.8.3
|
||||||
hooks:
|
hooks:
|
||||||
- id: blacken-docs
|
- id: flake8
|
||||||
args: [--target-version=py38]
|
additional_dependencies: [flake8-2020, flake8-implicit-str-concat]
|
||||||
additional_dependencies: [black]
|
|
||||||
|
- repo: https://github.com/asottile/seed-isort-config
|
||||||
|
rev: v2.2.0
|
||||||
|
hooks:
|
||||||
|
- id: seed-isort-config
|
||||||
|
|
||||||
|
- repo: https://github.com/timothycrosley/isort
|
||||||
|
rev: 4.3.21
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
|
||||||
|
- repo: https://github.com/pre-commit/pygrep-hooks
|
||||||
|
rev: v1.5.1
|
||||||
|
hooks:
|
||||||
|
- id: python-check-blanket-noqa
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.6.0
|
rev: v3.1.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-added-large-files
|
|
||||||
- id: check-case-conflict
|
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
- id: check-json
|
|
||||||
- id: check-toml
|
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: debug-statements
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: forbid-submodules
|
|
||||||
- id: trailing-whitespace
|
|
||||||
exclude: .github/(ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE).md
|
|
||||||
|
|
||||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
|
||||||
rev: 0.28.6
|
|
||||||
hooks:
|
|
||||||
- id: check-github-workflows
|
|
||||||
- id: check-renovate
|
|
||||||
|
|
||||||
- repo: https://github.com/rhysd/actionlint
|
|
||||||
rev: v1.7.1
|
|
||||||
hooks:
|
|
||||||
- id: actionlint
|
|
||||||
|
|
||||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
||||||
rev: 2.1.3
|
|
||||||
hooks:
|
|
||||||
- id: pyproject-fmt
|
|
||||||
|
|
||||||
- repo: https://github.com/abravalheri/validate-pyproject
|
|
||||||
rev: v0.18
|
|
||||||
hooks:
|
|
||||||
- id: validate-pyproject
|
|
||||||
|
|
||||||
- repo: https://github.com/tox-dev/tox-ini-fmt
|
|
||||||
rev: 1.3.1
|
|
||||||
hooks:
|
|
||||||
- id: tox-ini-fmt
|
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
|
||||||
rev: v4.0.0-alpha.8
|
|
||||||
hooks:
|
|
||||||
- id: prettier
|
|
||||||
args: [--prose-wrap=always, --print-width=88]
|
|
||||||
exclude: .github/(ISSUE_TEMPLATE|PULL_REQUEST_TEMPLATE).md
|
|
||||||
|
|
||||||
- repo: meta
|
|
||||||
hooks:
|
|
||||||
- id: check-hooks-apply
|
|
||||||
- id: check-useless-excludes
|
|
||||||
|
|
||||||
ci:
|
|
||||||
autoupdate_schedule: quarterly
|
|
||||||
|
|
9
.scrutinizer.yml
Normal file
9
.scrutinizer.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
checks:
|
||||||
|
python:
|
||||||
|
code_rating: true
|
||||||
|
duplicate_code: true
|
||||||
|
filter:
|
||||||
|
excluded_paths:
|
||||||
|
- '*/test/*'
|
||||||
|
tools:
|
||||||
|
external_code_coverage: true
|
67
.travis.yml
Normal file
67
.travis.yml
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
language: python
|
||||||
|
cache:
|
||||||
|
pip: true
|
||||||
|
directories:
|
||||||
|
- $HOME/.cache/pre-commit
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- secure: ivg6II471E9HV8xyqnawLIuP/sZ0J63Y+BC0BQcRVKtLn/K3zmD1ozM3TFL9S549Nxd0FqDKHXJvXsgaTGIDpK8sxE2AMKV5IojyM0iAVuN7YjPK9vwSlRw1u0EysPMFqxOZVQnoDyHrSGIUrP/VMdnhBu6dbUX0FyEkvZshXhY=
|
||||||
|
- secure: gDWNEYA1EUv4G230/KzcTgcmEST0nf2FeW/z/prsoQBu+TWw1rKKSJAJeMLvuI1z4aYqqNYdmqjWyNhhVK3p5wmFP2lxbhaBT1jDsxxFpePc0nUkdAQOOD0yBpbBGkqkjjxU34HjTX2NFNEbcM3izVVE9oQmS5r4oFFNJgdL91c=
|
||||||
|
- secure: RpsZblHFU7a5dnkO/JUgi70RkNJwoUh3jJqVo1oOLjL+lvuAmPXhI8MDk2diUk43X+XCBFBEnm7UCGnjUF+hDnobO4T+VrIFuVJWg3C7iKIT+YWvgG6A+CSeo/P0I0dAeUscTr5z4ylOq3EDx4MFSa8DmoWMmjKTAG1GAeTlY2k=
|
||||||
|
- secure: T5OKyd5Bs0nZbUr+YICbThC5GrFq/kUjX8FokzCv7NWsYaUWIwEmMXXzoYALoB3A+rAglOx6GABaupoNKKg3tFQyxXphuMKpZ8MasMAMFjFW0d7wsgGy0ylhVwrgoKzDbCQ5FKbohC+9ltLs+kKMCQ0L+MI70a/zTfF4/dVWO/o=
|
||||||
|
- secure: DxBvGGoIgbAeuuU3A6+J1HBbmUAEvqdmK73etw+yNKDLGvvukgTL33dNCr8CZXLKRRvfhrjU7Q01GUpOTxrVQ9nJgsD55kwx0wPtuBWIF80M2m4SPsiVLlwP/LFYD5JMDTDWjFTlVahma8P7qoLjCc7b/RgigWLidH19snQmjdY=
|
||||||
|
- secure: VPARlWNg/0Nit7a924vJlDfv7yiuTDtrcGZNFrZ6yN3dl8ZjVPizQXQNKA3yq0y2jW25nwjRwZYj3eY5MdM9F7Sw51d+/8AjFtdCuRgDvwlQFR/pCoyzqgJATkXKo7mlejvnA+5EKUzAmu3drIbboFgbLgRTMrG7b/ot9tazTHs=
|
||||||
|
- secure: CQYL7MH6tSVrCcluIfWfDSTo4E/p+9pF0eI7Vtf0oaZBzyulODHK8h/mzJp4HwezyfOu0RCedq6sloGQr1/29CvWWESaYyoGoGz9Mz2ZS+MpIcjGISfZa+x4vSp6QPFvd4i/1Z/1j2gJVVyswkrIVUwZIDJtfAKzZI5iHx2gH8Y=
|
||||||
|
- secure: SsKJoJwtDVWrL5xxl9C/gTRy6FhfRQQNNAFOogl9mTs/WeI2t9QTYoKsxLPXOdoRdu4MvT3h/B2sjwggt7zP81fBVxQRTkg4nq0zSHlj0NqclbFa6I5lUYdGwH9gPk/HWJJwXhKRDsqn/iRw2v+qBDs/j3kIgPQ0yjM58LEPXic=
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
fast_finish: true
|
||||||
|
include:
|
||||||
|
- python: 3.8
|
||||||
|
env: TOXENV=lint
|
||||||
|
- python: 3.8
|
||||||
|
- python: 3.7
|
||||||
|
- python: 3.6
|
||||||
|
- python: 3.5
|
||||||
|
- python: 3.9-dev
|
||||||
|
- python: 3.10-dev
|
||||||
|
- python: pypy3
|
||||||
|
|
||||||
|
install:
|
||||||
|
- travis_retry pip install -U pip
|
||||||
|
- travis_retry pip install -U tox-travis
|
||||||
|
|
||||||
|
script: tox
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- |
|
||||||
|
if [ "$TOXENV" != "lint" ]; then
|
||||||
|
travis_retry pip install -U coveralls && coveralls
|
||||||
|
travis_retry pip install -U codecov && codecov
|
||||||
|
fi
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
- provider: pypi
|
||||||
|
server: https://test.pypi.org/legacy/
|
||||||
|
on:
|
||||||
|
tags: false
|
||||||
|
repo: pylast/pylast
|
||||||
|
branch: master
|
||||||
|
condition: $TOXENV = lint
|
||||||
|
user: hugovk
|
||||||
|
password:
|
||||||
|
secure: "OCNT7Sf7TpS6aKuqBXEWxJZjmEpdERTBp/yllOd9xnpFt2ZL96CyKtAhPA8zu5OP58QFEZSafZRfXYJoz78RDrx3gOdRXCFT00vXIMnjVvrAlieNEHCVAT0kRW9lYK1Cf5baHYsOYIs6EZf2fEAhdzvmh83G4Y1Y+FPR9tA6uy8="
|
||||||
|
distributions: sdist --format=gztar bdist_wheel
|
||||||
|
skip_existing: true
|
||||||
|
- provider: pypi
|
||||||
|
on:
|
||||||
|
tags: true
|
||||||
|
repo: pylast/pylast
|
||||||
|
branch: master
|
||||||
|
condition: $TOXENV = lint
|
||||||
|
user: hugovk
|
||||||
|
password:
|
||||||
|
secure: "OCNT7Sf7TpS6aKuqBXEWxJZjmEpdERTBp/yllOd9xnpFt2ZL96CyKtAhPA8zu5OP58QFEZSafZRfXYJoz78RDrx3gOdRXCFT00vXIMnjVvrAlieNEHCVAT0kRW9lYK1Cf5baHYsOYIs6EZf2fEAhdzvmh83G4Y1Y+FPR9tA6uy8="
|
||||||
|
distributions: sdist --format=gztar bdist_wheel
|
||||||
|
skip_existing: true
|
124
CHANGELOG.md
124
CHANGELOG.md
|
@ -1,144 +1,95 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## 4.2.1 and newer
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
See GitHub Releases:
|
|
||||||
|
|
||||||
- https://github.com/pylast/pylast/releases
|
|
||||||
|
|
||||||
## [4.2.0] - 2021-03-14
|
|
||||||
|
|
||||||
## Changed
|
|
||||||
|
|
||||||
- Fix unsafe creation of temp file for caching, and improve exception raising (#356)
|
|
||||||
@kvanzuijlen
|
|
||||||
- [pre-commit.ci] pre-commit autoupdate (#362) @pre-commit-ci
|
|
||||||
|
|
||||||
## [4.1.0] - 2021-01-04
|
|
||||||
|
|
||||||
## Added
|
|
||||||
|
|
||||||
- Add support for streaming (#336) @kvanzuijlen
|
|
||||||
- Add Python 3.9 final to Travis CI (#350) @sheetalsingala
|
|
||||||
|
|
||||||
## Changed
|
|
||||||
|
|
||||||
- Update copyright year (#360) @hugovk
|
|
||||||
- Replace Travis CI with GitHub Actions (#352) @hugovk
|
|
||||||
- [pre-commit.ci] pre-commit autoupdate (#359) @pre-commit-ci
|
|
||||||
|
|
||||||
## Fixed
|
|
||||||
|
|
||||||
- Set limit to 50 by default, not 1 (#355) @hugovk
|
|
||||||
|
|
||||||
## [4.0.0] - 2020-10-07
|
|
||||||
|
|
||||||
## Added
|
|
||||||
|
|
||||||
- Add support for Python 3.9 (#347) @hugovk
|
|
||||||
|
|
||||||
## Removed
|
|
||||||
|
|
||||||
- Remove deprecated `Artist.get_cover_image`, `User.get_artist_tracks` and
|
|
||||||
`STATUS_TOKEN_ERROR` (#348) @hugovk
|
|
||||||
- Drop support for EOL Python 3.5 (#346) @hugovk
|
|
||||||
|
|
||||||
## [3.3.0] - 2020-06-25
|
## [3.3.0] - 2020-06-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- `User.get_now_playing`: Add album and cover image to info (#330) @hugovk
|
* `User.get_now_playing`: Add album and cover image to info (#330) @hugovk
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Improve handling of error responses from the API (#327) @spiritualized
|
* Improve handling of error responses from the API (#327) @spiritualized
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- Deprecate `Artist.get_cover_image`, they're no longer available from Last.fm (#332)
|
* Deprecate `Artist.get_cover_image`, they're no longer available from Last.fm (#332) @hugovk
|
||||||
@hugovk
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fix `artist.get_bio_content()` to return `None` if bio is empty (#326) @hugovk
|
* Fix `artist.get_bio_content()` to return `None` if bio is empty (#326) @hugovk
|
||||||
|
|
||||||
|
|
||||||
## [3.2.1] - 2020-03-05
|
## [3.2.1] - 2020-03-05
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Only Python 3 is supported: don't create universal wheel (#318) @hugovk
|
* Only Python 3 is supported: don't create universal wheel (#318) @hugovk
|
||||||
- Fix regression calling `get_recent_tracks` with `limit=None` (#320) @hugovk
|
* Fix regression calling `get_recent_tracks` with `limit=None` (#320) @hugovk
|
||||||
- Fix `DeprecationWarning`: Please use `assertRegex` instead (#323) @hugovk
|
* Fix `DeprecationWarning`: Please use `assertRegex` instead (#323) @hugovk
|
||||||
|
|
||||||
## [3.2.0] - 2020-01-03
|
## [3.2.0] - 2020-01-03
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Support for Python 3.8
|
* Support for Python 3.8
|
||||||
- Store album art URLs when you call `GetTopAlbums` ([#307])
|
* Store album art URLs when you call `GetTopAlbums` ([#307])
|
||||||
- Retry paging through results on exception ([#297])
|
* Retry paging through results on exception ([#297])
|
||||||
- More error status codes from https://last.fm/api/errorcodes ([#297])
|
* More error status codes from https://last.fm/api/errorcodes ([#297])
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Respect `get_recent_tracks`' limit when there's a now playing track ([#310])
|
* Respect `get_recent_tracks`' limit when there's a now playing track ([#310])
|
||||||
- Move installable code to `src/` ([#301])
|
* Move installable code to `src/` ([#301])
|
||||||
- Update `get_weekly_artist_charts` docstring: only for `User` ([#311])
|
* Update `get_weekly_artist_charts` docstring: only for `User` ([#311])
|
||||||
- Remove Python 2 warnings, `python_requires` should be enough ([#312])
|
* Remove Python 2 warnings, `python_requires` should be enough ([#312])
|
||||||
- Use setuptools_scm to simplify versioning during release ([#316])
|
* Use setuptools_scm to simplify versioning during release ([#316])
|
||||||
- Various lint and test updates
|
* Various lint and test updates
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- Last.fm's `user.getArtistTracks` has now been deprecated by Last.fm and is no longer
|
* Last.fm's `user.getArtistTracks` has now been deprecated by Last.fm and is no longer
|
||||||
available. Last.fm returns a "Deprecated - This type of request is no longer
|
available. Last.fm returns a "Deprecated - This type of request is no longer
|
||||||
supported" error when calling it. A future version of pylast will remove its
|
supported" error when calling it. A future version of pylast will remove its
|
||||||
`User.get_artist_tracks` altogether. ([#305])
|
`User.get_artist_tracks` altogether. ([#305])
|
||||||
|
|
||||||
- `STATUS_TOKEN_ERROR` is deprecated and will be removed in a future version. Use
|
* `STATUS_TOKEN_ERROR` is deprecated and will be removed in a future version.
|
||||||
`STATUS_OPERATION_FAILED` instead.
|
Use `STATUS_OPERATION_FAILED` instead.
|
||||||
|
|
||||||
## [3.1.0] - 2019-03-07
|
## [3.1.0] - 2019-03-07
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Extract username from session via new
|
* Extract username from session via new
|
||||||
`SessionKeyGenerator.get_web_auth_session_key_username` ([#290])
|
`SessionKeyGenerator.get_web_auth_session_key_username` ([#290])
|
||||||
- `User.get_track_scrobbles` ([#298])
|
* `User.get_track_scrobbles` ([#298])
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- `User.get_artist_tracks`. Use `User.get_track_scrobbles` as a partial replacement.
|
* `User.get_artist_tracks`. Use `User.get_track_scrobbles` as a partial replacement.
|
||||||
([#298])
|
([#298])
|
||||||
|
|
||||||
## [3.0.0] - 2019-01-01
|
## [3.0.0] - 2019-01-01
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
* This changelog file ([#273])
|
||||||
- This changelog file ([#273])
|
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
- Support for Python 2.7 ([#265])
|
* Support for Python 2.7 ([#265])
|
||||||
|
|
||||||
- Constants `COVER_SMALL`, `COVER_MEDIUM`, `COVER_LARGE`, `COVER_EXTRA_LARGE` and
|
* Constants `COVER_SMALL`, `COVER_MEDIUM`, `COVER_LARGE`, `COVER_EXTRA_LARGE`
|
||||||
`COVER_MEGA`. Use `SIZE_SMALL` etc. instead. ([#282])
|
and `COVER_MEGA`. Use `SIZE_SMALL` etc. instead. ([#282])
|
||||||
|
|
||||||
## [2.4.0] - 2018-08-08
|
## [2.4.0] - 2018-08-08
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
- Support for Python 2.7 ([#265])
|
* Support for Python 2.7 ([#265])
|
||||||
|
|
||||||
[4.2.0]: https://github.com/pylast/pylast/compare/4.1.0...4.2.0
|
[3.3.0]: https://github.com/pylast/pylast/compare/v3.2.1...3.3.0
|
||||||
[4.1.0]: https://github.com/pylast/pylast/compare/4.0.0...4.1.0
|
[3.2.1]: https://github.com/pylast/pylast/compare/v3.2.0...3.2.1
|
||||||
[4.0.0]: https://github.com/pylast/pylast/compare/3.3.0...4.0.0
|
[3.2.0]: https://github.com/pylast/pylast/compare/v3.1.0...3.2.0
|
||||||
[3.3.0]: https://github.com/pylast/pylast/compare/3.2.1...3.3.0
|
[3.1.0]: https://github.com/pylast/pylast/compare/v3.0.0...3.1.0
|
||||||
[3.2.1]: https://github.com/pylast/pylast/compare/3.2.0...3.2.1
|
|
||||||
[3.2.0]: https://github.com/pylast/pylast/compare/3.1.0...3.2.0
|
|
||||||
[3.1.0]: https://github.com/pylast/pylast/compare/3.0.0...3.1.0
|
|
||||||
[3.0.0]: https://github.com/pylast/pylast/compare/2.4.0...3.0.0
|
[3.0.0]: https://github.com/pylast/pylast/compare/2.4.0...3.0.0
|
||||||
[2.4.0]: https://github.com/pylast/pylast/compare/2.3.0...2.4.0
|
[2.4.0]: https://github.com/pylast/pylast/compare/2.3.0...2.4.0
|
||||||
[#265]: https://github.com/pylast/pylast/issues/265
|
[#265]: https://github.com/pylast/pylast/issues/265
|
||||||
|
@ -154,6 +105,3 @@ See GitHub Releases:
|
||||||
[#311]: https://github.com/pylast/pylast/issues/311
|
[#311]: https://github.com/pylast/pylast/issues/311
|
||||||
[#312]: https://github.com/pylast/pylast/issues/312
|
[#312]: https://github.com/pylast/pylast/issues/312
|
||||||
[#316]: https://github.com/pylast/pylast/issues/316
|
[#316]: https://github.com/pylast/pylast/issues/316
|
||||||
[#346]: https://github.com/pylast/pylast/issues/346
|
|
||||||
[#347]: https://github.com/pylast/pylast/issues/347
|
|
||||||
[#348]: https://github.com/pylast/pylast/issues/348
|
|
||||||
|
|
156
README.md
156
README.md
|
@ -1,65 +1,61 @@
|
||||||
# pyLast
|
pyLast
|
||||||
|
======
|
||||||
|
|
||||||
[](https://pypi.org/project/pylast/)
|
[](https://pypi.org/project/pylast/)
|
||||||
[](https://pypi.org/project/pylast/)
|
[](https://pypi.org/project/pylast/)
|
||||||
[](https://pypistats.org/packages/pylast)
|
[](https://pypistats.org/packages/pylast)
|
||||||
[](https://github.com/pylast/pylast/actions)
|
[](https://travis-ci.org/pylast/pylast)
|
||||||
[](https://codecov.io/gh/pylast/pylast)
|
[](https://codecov.io/gh/pylast/pylast)
|
||||||
[](https://github.com/psf/black)
|
[](https://coveralls.io/github/pylast/pylast?branch=master)
|
||||||
|
[](https://github.com/python/black)
|
||||||
[](https://zenodo.org/badge/latestdoi/7803088)
|
[](https://zenodo.org/badge/latestdoi/7803088)
|
||||||
|
|
||||||
A Python interface to [Last.fm](https://www.last.fm/) and other API-compatible websites
|
A Python interface to [Last.fm](https://www.last.fm/) and other API-compatible websites such as [Libre.fm](https://libre.fm/).
|
||||||
such as [Libre.fm](https://libre.fm/).
|
|
||||||
|
|
||||||
Use the pydoc utility for help on usage or see [tests/](tests/) for examples.
|
Use the pydoc utility for help on usage or see [tests/](tests/) for examples.
|
||||||
|
|
||||||
## Installation
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
Install via pip:
|
||||||
|
|
||||||
|
pip install pylast
|
||||||
|
|
||||||
Install latest development version:
|
Install latest development version:
|
||||||
|
|
||||||
```sh
|
pip install -U git+https://github.com/pylast/pylast
|
||||||
python3 -m pip install -U git+https://git.hirad.it/Hirad/pylast
|
|
||||||
```
|
|
||||||
|
|
||||||
Or from requirements.txt:
|
Or from requirements.txt:
|
||||||
|
|
||||||
```txt
|
-e git://github.com/pylast/pylast.git#egg=pylast
|
||||||
-e https://git.hirad.it/Hirad/pylast#egg=pylast
|
|
||||||
```
|
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
|
||||||
- pyLast 5.3+ supports Python 3.8-3.13.
|
* pylast 3.0.0+ supports Python 3.5+ ([#265](https://github.com/pylast/pylast/issues/265))
|
||||||
- pyLast 5.2+ supports Python 3.8-3.12.
|
* pyLast 2.2.0 - 2.4.0 supports Python 2.7.10+, 3.4, 3.5, 3.6, 3.7.
|
||||||
- pyLast 5.1 supports Python 3.7-3.11.
|
* pyLast 2.0.0 - 2.1.0 supports Python 2.7.10+, 3.4, 3.5, 3.6.
|
||||||
- pyLast 5.0 supports Python 3.7-3.10.
|
* pyLast 1.7.0 - 1.9.0 supports Python 2.7, 3.3, 3.4, 3.5, 3.6.
|
||||||
- pyLast 4.3 - 4.5 supports Python 3.6-3.10.
|
* pyLast 1.0.0 - 1.6.0 supports Python 2.7, 3.3, 3.4.
|
||||||
- pyLast 4.0 - 4.2 supports Python 3.6-3.9.
|
* pyLast 0.5 supports Python 2, 3.
|
||||||
- pyLast 3.2 - 3.3 supports Python 3.5-3.8.
|
* pyLast < 0.5 supports Python 2.
|
||||||
- pyLast 3.0 - 3.1 supports Python 3.5-3.7.
|
|
||||||
- pyLast 2.2 - 2.4 supports Python 2.7.10+, 3.4-3.7.
|
|
||||||
- pyLast 2.0 - 2.1 supports Python 2.7.10+, 3.4-3.6.
|
|
||||||
- pyLast 1.7 - 1.9 supports Python 2.7, 3.3-3.6.
|
|
||||||
- pyLast 1.0 - 1.6 supports Python 2.7, 3.3-3.4.
|
|
||||||
- pyLast 0.5 supports Python 2, 3.
|
|
||||||
- pyLast < 0.5 supports Python 2.
|
|
||||||
|
|
||||||
## Features
|
Features
|
||||||
|
--------
|
||||||
|
|
||||||
- Simple public interface.
|
* Simple public interface.
|
||||||
- Access to all the data exposed by the Last.fm web services.
|
* Access to all the data exposed by the Last.fm web services.
|
||||||
- Scrobbling support.
|
* Scrobbling support.
|
||||||
- Full object-oriented design.
|
* Full object-oriented design.
|
||||||
- Proxy support.
|
* Proxy support.
|
||||||
- Internal caching support for some web services calls (disabled by default).
|
* Internal caching support for some web services calls (disabled by default).
|
||||||
- Support for other API-compatible networks like Libre.fm.
|
* Support for other API-compatible networks like Libre.fm.
|
||||||
|
* Python 3-friendly (Starting from 0.5).
|
||||||
|
|
||||||
## Getting started
|
|
||||||
|
|
||||||
Here's some simple code example to get you started. In order to create any object from
|
Getting started
|
||||||
pyLast, you need a `Network` object which represents a social music network that is
|
---------------
|
||||||
Last.fm or any other API-compatible one. You can obtain a pre-configured one for Last.fm
|
|
||||||
and use it as follows:
|
Here's some simple code example to get you started. In order to create any object from pyLast, you need a `Network` object which represents a social music network that is Last.fm or any other API-compatible one. You can obtain a pre-configured one for Last.fm and use it as follows:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import pylast
|
import pylast
|
||||||
|
@ -73,50 +69,14 @@ API_SECRET = "425b55975eed76058ac220b7b4e8a054"
|
||||||
username = "your_user_name"
|
username = "your_user_name"
|
||||||
password_hash = pylast.md5("your_password")
|
password_hash = pylast.md5("your_password")
|
||||||
|
|
||||||
network = pylast.LastFMNetwork(
|
network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET,
|
||||||
api_key=API_KEY,
|
username=username, password_hash=password_hash)
|
||||||
api_secret=API_SECRET,
|
|
||||||
username=username,
|
|
||||||
password_hash=password_hash,
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively, instead of creating `network` with a username and password, you can
|
|
||||||
authenticate with a session key:
|
|
||||||
|
|
||||||
```python
|
|
||||||
import pylast
|
|
||||||
|
|
||||||
SESSION_KEY_FILE = os.path.join(os.path.expanduser("~"), ".session_key")
|
|
||||||
network = pylast.LastFMNetwork(API_KEY, API_SECRET)
|
|
||||||
if not os.path.exists(SESSION_KEY_FILE):
|
|
||||||
skg = pylast.SessionKeyGenerator(network)
|
|
||||||
url = skg.get_web_auth_url()
|
|
||||||
|
|
||||||
print(f"Please authorize this script to access your account: {url}\n")
|
|
||||||
import time
|
|
||||||
import webbrowser
|
|
||||||
|
|
||||||
webbrowser.open(url)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
session_key = skg.get_web_auth_session_key(url)
|
|
||||||
with open(SESSION_KEY_FILE, "w") as f:
|
|
||||||
f.write(session_key)
|
|
||||||
break
|
|
||||||
except pylast.WSError:
|
|
||||||
time.sleep(1)
|
|
||||||
else:
|
|
||||||
session_key = open(SESSION_KEY_FILE).read()
|
|
||||||
|
|
||||||
network.session_key = session_key
|
|
||||||
```
|
|
||||||
|
|
||||||
And away we go:
|
|
||||||
|
|
||||||
```python
|
|
||||||
# Now you can use that object everywhere
|
# Now you can use that object everywhere
|
||||||
|
artist = network.get_artist("System of a Down")
|
||||||
|
artist.shout("<3")
|
||||||
|
|
||||||
|
|
||||||
track = network.get_track("Iron Maiden", "The Nomad")
|
track = network.get_track("Iron Maiden", "The Nomad")
|
||||||
track.love()
|
track.love()
|
||||||
track.add_tags(("awesome", "favorite"))
|
track.add_tags(("awesome", "favorite"))
|
||||||
|
@ -125,20 +85,14 @@ track.add_tags(("awesome", "favorite"))
|
||||||
# to get more help about anything and see examples of how it works
|
# to get more help about anything and see examples of how it works
|
||||||
```
|
```
|
||||||
|
|
||||||
More examples in
|
More examples in <a href="https://github.com/hugovk/lastfm-tools">hugovk/lastfm-tools</a> and [tests/](tests/).
|
||||||
<a href="https://github.com/hugovk/lastfm-tools">hugovk/lastfm-tools</a> and
|
|
||||||
[tests/](https://github.com/pylast/pylast/tree/main/tests).
|
|
||||||
|
|
||||||
## Testing
|
Testing
|
||||||
|
-------
|
||||||
|
|
||||||
The [tests/](https://github.com/pylast/pylast/tree/main/tests) directory contains
|
The [tests/](tests/) directory contains integration and unit tests with Last.fm, and plenty of code examples.
|
||||||
integration and unit tests with Last.fm, and plenty of code examples.
|
|
||||||
|
|
||||||
For integration tests you need a test account at Last.fm that will become cluttered with
|
For integration tests you need a test account at Last.fm that will become cluttered with test data, and an API key and secret. Either copy [example_test_pylast.yaml](example_test_pylast.yaml) to test_pylast.yaml and fill out the credentials, or set them as environment variables like:
|
||||||
test data, and an API key and secret. Either copy
|
|
||||||
[example_test_pylast.yaml](https://github.com/pylast/pylast/blob/main/example_test_pylast.yaml)
|
|
||||||
to test_pylast.yaml and fill out the credentials, or set them as environment variables
|
|
||||||
like:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
export PYLAST_USERNAME=TODO_ENTER_YOURS_HERE
|
export PYLAST_USERNAME=TODO_ENTER_YOURS_HERE
|
||||||
|
@ -148,20 +102,17 @@ export PYLAST_API_SECRET=TODO_ENTER_YOURS_HERE
|
||||||
```
|
```
|
||||||
|
|
||||||
To run all unit and integration tests:
|
To run all unit and integration tests:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
python3 -m pip install -e ".[tests]"
|
pip install pytest flaky
|
||||||
pytest
|
pytest
|
||||||
```
|
```
|
||||||
|
|
||||||
Or run just one test case:
|
Or run just one test case:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
pytest -k test_scrobble
|
pytest -k test_scrobble
|
||||||
```
|
```
|
||||||
|
|
||||||
To run with coverage:
|
To run with coverage:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
pytest -v --cov pylast --cov-report term-missing
|
pytest -v --cov pylast --cov-report term-missing
|
||||||
coverage report # for command-line report
|
coverage report # for command-line report
|
||||||
|
@ -169,7 +120,8 @@ coverage html # for HTML report
|
||||||
open htmlcov/index.html
|
open htmlcov/index.html
|
||||||
```
|
```
|
||||||
|
|
||||||
## Logging
|
Logging
|
||||||
|
-------
|
||||||
|
|
||||||
To enable from your own code:
|
To enable from your own code:
|
||||||
|
|
||||||
|
@ -177,8 +129,7 @@ To enable from your own code:
|
||||||
import logging
|
import logging
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
network = pylast.LastFMNetwork(...)
|
network = pylast.LastFMNetwork(...)
|
||||||
```
|
```
|
||||||
|
@ -186,8 +137,5 @@ network = pylast.LastFMNetwork(...)
|
||||||
To enable from pytest:
|
To enable from pytest:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
pytest --log-cli-level info -k test_album_search_images
|
pytest --log-cli-level debug -k test_album_search_images
|
||||||
```
|
```
|
||||||
|
|
||||||
To also see data returned from the API, use `level=logging.DEBUG` or
|
|
||||||
`--log-cli-level debug` instead.
|
|
||||||
|
|
22
RELEASING.md
22
RELEASING.md
|
@ -1,22 +1,22 @@
|
||||||
# Release Checklist
|
# Release Checklist
|
||||||
|
|
||||||
- [ ] Get `main` to the appropriate code release state.
|
* [ ] Get master to the appropriate code release state.
|
||||||
[GitHub Actions](https://github.com/pylast/pylast/actions) should be running
|
[Travis CI](https://travis-ci.org/pylast/pylast) should be running cleanly for
|
||||||
cleanly for all merges to `main`.
|
all merges to master.
|
||||||
[](https://github.com/pylast/pylast/actions)
|
|
||||||
|
|
||||||
- [ ] Edit release draft, adjust text if needed:
|
* [ ] Edit release draft, adjust text if needed:
|
||||||
https://github.com/pylast/pylast/releases
|
https://github.com/pylast/pylast/releases
|
||||||
|
|
||||||
- [ ] Check next tag is correct, amend if needed
|
* [ ] Check next tag is correct, amend if needed
|
||||||
|
|
||||||
- [ ] Publish release
|
* [ ] Copy text into [`CHANGELOG.md`](CHANGELOG.md)
|
||||||
|
|
||||||
- [ ] Check the tagged
|
* [ ] Publish release
|
||||||
[GitHub Actions build](https://github.com/pylast/pylast/actions/workflows/deploy.yml)
|
|
||||||
has deployed to [PyPI](https://pypi.org/project/pylast/#history)
|
|
||||||
|
|
||||||
- [ ] Check installation:
|
* [ ] Check the tagged [Travis CI build](https://travis-ci.org/pylast/pylast) has
|
||||||
|
deployed to [PyPI](https://pypi.org/project/pylast/#history)
|
||||||
|
|
||||||
|
* [ ] Check installation:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip3 uninstall -y pylast && pip3 install -U pylast && python3 -c "import pylast; print(pylast.__version__)"
|
pip3 uninstall -y pylast && pip3 install -U pylast && python3 -c "import pylast; print(pylast.__version__)"
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
[build-system]
|
|
||||||
build-backend = "hatchling.build"
|
|
||||||
requires = [
|
|
||||||
"hatch-vcs",
|
|
||||||
"hatchling",
|
|
||||||
]
|
|
||||||
|
|
||||||
[project]
|
|
||||||
name = "pylast"
|
|
||||||
description = "A Python interface to Last.fm and Libre.fm"
|
|
||||||
readme = "README.md"
|
|
||||||
keywords = [
|
|
||||||
"Last.fm",
|
|
||||||
"music",
|
|
||||||
"scrobble",
|
|
||||||
"scrobbling",
|
|
||||||
]
|
|
||||||
license = { text = "Apache-2.0" }
|
|
||||||
maintainers = [
|
|
||||||
{ name = "Hugo van Kemenade" },
|
|
||||||
]
|
|
||||||
authors = [
|
|
||||||
{ name = "Amr Hassan <amr.hassan@gmail.com> and Contributors", email = "amr.hassan@gmail.com" },
|
|
||||||
]
|
|
||||||
requires-python = ">=3.8"
|
|
||||||
classifiers = [
|
|
||||||
"Development Status :: 5 - Production/Stable",
|
|
||||||
"License :: OSI Approved :: Apache Software License",
|
|
||||||
"Programming Language :: Python :: 3 :: Only",
|
|
||||||
"Programming Language :: Python :: 3.8",
|
|
||||||
"Programming Language :: Python :: 3.9",
|
|
||||||
"Programming Language :: Python :: 3.10",
|
|
||||||
"Programming Language :: Python :: 3.11",
|
|
||||||
"Programming Language :: Python :: 3.12",
|
|
||||||
"Programming Language :: Python :: 3.13",
|
|
||||||
"Programming Language :: Python :: Implementation :: CPython",
|
|
||||||
"Programming Language :: Python :: Implementation :: PyPy",
|
|
||||||
"Topic :: Internet",
|
|
||||||
"Topic :: Multimedia :: Sound/Audio",
|
|
||||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
||||||
]
|
|
||||||
dynamic = [
|
|
||||||
"version",
|
|
||||||
]
|
|
||||||
dependencies = [
|
|
||||||
"httpx",
|
|
||||||
]
|
|
||||||
optional-dependencies.tests = [
|
|
||||||
"flaky",
|
|
||||||
"pytest",
|
|
||||||
"pytest-cov",
|
|
||||||
"pytest-random-order",
|
|
||||||
"pyyaml",
|
|
||||||
]
|
|
||||||
urls.Changelog = "https://github.com/pylast/pylast/releases"
|
|
||||||
urls.Homepage = "https://github.com/pylast/pylast"
|
|
||||||
urls.Source = "https://github.com/pylast/pylast"
|
|
||||||
|
|
||||||
[tool.hatch]
|
|
||||||
version.source = "vcs"
|
|
||||||
|
|
||||||
[tool.hatch.version.raw-options]
|
|
||||||
local_scheme = "no-local-version"
|
|
||||||
|
|
||||||
[tool.ruff]
|
|
||||||
fix = true
|
|
||||||
|
|
||||||
lint.select = [
|
|
||||||
"C4", # flake8-comprehensions
|
|
||||||
"E", # pycodestyle errors
|
|
||||||
"EM", # flake8-errmsg
|
|
||||||
"F", # pyflakes errors
|
|
||||||
"I", # isort
|
|
||||||
"ISC", # flake8-implicit-str-concat
|
|
||||||
"LOG", # flake8-logging
|
|
||||||
"PGH", # pygrep-hooks
|
|
||||||
"RUF022", # unsorted-dunder-all
|
|
||||||
"RUF100", # unused noqa (yesqa)
|
|
||||||
"UP", # pyupgrade
|
|
||||||
"W", # pycodestyle warnings
|
|
||||||
"YTT", # flake8-2020
|
|
||||||
]
|
|
||||||
lint.extend-ignore = [
|
|
||||||
"E203", # Whitespace before ':'
|
|
||||||
"E221", # Multiple spaces before operator
|
|
||||||
"E226", # Missing whitespace around arithmetic operator
|
|
||||||
"E241", # Multiple spaces after ','
|
|
||||||
]
|
|
||||||
lint.isort.known-first-party = [
|
|
||||||
"pylast",
|
|
||||||
]
|
|
||||||
lint.isort.required-imports = [
|
|
||||||
"from __future__ import annotations",
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.pyproject-fmt]
|
|
||||||
max_supported_python = "3.13"
|
|
|
@ -2,5 +2,3 @@
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
once::DeprecationWarning
|
once::DeprecationWarning
|
||||||
once::PendingDeprecationWarning
|
once::PendingDeprecationWarning
|
||||||
|
|
||||||
xfail_strict=true
|
|
||||||
|
|
6
setup.cfg
Normal file
6
setup.cfg
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[flake8]
|
||||||
|
ignore = W503
|
||||||
|
max_line_length = 88
|
||||||
|
|
||||||
|
[tool:isort]
|
||||||
|
known_third_party = flaky,pkg_resources,pylast,pytest,setuptools
|
46
setup.py
Executable file
46
setup.py
Executable file
|
@ -0,0 +1,46 @@
|
||||||
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
with open("README.md") as f:
|
||||||
|
long_description = f.read()
|
||||||
|
|
||||||
|
|
||||||
|
def local_scheme(version):
|
||||||
|
"""Skip the local version (eg. +xyz of 0.6.1.dev4+gdf99fe2)
|
||||||
|
to be able to upload to Test PyPI"""
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name="pylast",
|
||||||
|
description="A Python interface to Last.fm and Libre.fm",
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
author="Amr Hassan <amr.hassan@gmail.com> and Contributors",
|
||||||
|
author_email="amr.hassan@gmail.com",
|
||||||
|
url="https://github.com/pylast/pylast",
|
||||||
|
license="Apache2",
|
||||||
|
keywords=["Last.fm", "music", "scrobble", "scrobbling"],
|
||||||
|
packages=find_packages(where="src"),
|
||||||
|
package_dir={"": "src"},
|
||||||
|
use_scm_version={"local_scheme": local_scheme},
|
||||||
|
setup_requires=["setuptools_scm"],
|
||||||
|
extras_require={
|
||||||
|
"tests": ["flaky", "pytest", "pytest-cov", "pytest-random-order", "pyyaml"]
|
||||||
|
},
|
||||||
|
python_requires=">=3.5",
|
||||||
|
classifiers=[
|
||||||
|
"Development Status :: 5 - Production/Stable",
|
||||||
|
"License :: OSI Approved :: Apache Software License",
|
||||||
|
"Topic :: Internet",
|
||||||
|
"Topic :: Multimedia :: Sound/Audio",
|
||||||
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Programming Language :: Python :: 3.5",
|
||||||
|
"Programming Language :: Python :: 3.6",
|
||||||
|
"Programming Language :: Python :: 3.7",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
|
],
|
||||||
|
)
|
File diff suppressed because it is too large
Load diff
|
@ -2,15 +2,13 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastAlbum(TestPyLastWithLastFm):
|
class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
def test_album_tags_are_topitems(self) -> None:
|
def test_album_tags_are_topitems(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = self.network.get_album("Test Artist", "Test Album")
|
album = self.network.get_album("Test Artist", "Test Album")
|
||||||
|
|
||||||
|
@ -21,25 +19,25 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
assert len(tags) > 0
|
assert len(tags) > 0
|
||||||
assert isinstance(tags[0], pylast.TopItem)
|
assert isinstance(tags[0], pylast.TopItem)
|
||||||
|
|
||||||
def test_album_is_hashable(self) -> None:
|
def test_album_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = self.network.get_album("Test Artist", "Test Album")
|
album = self.network.get_album("Test Artist", "Test Album")
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_is_thing_hashable(album)
|
self.helper_is_thing_hashable(album)
|
||||||
|
|
||||||
def test_album_in_recent_tracks(self) -> None:
|
def test_album_in_recent_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
# limit=2 to ignore now-playing:
|
# limit=2 to ignore now-playing:
|
||||||
track = list(lastfm_user.get_recent_tracks(limit=2))[0]
|
track = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert hasattr(track, "album")
|
assert hasattr(track, "album")
|
||||||
|
|
||||||
def test_album_wiki_content(self) -> None:
|
def test_album_wiki_content(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = pylast.Album("Test Artist", "Test Album", self.network)
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
assert wiki is not None
|
assert wiki is not None
|
||||||
assert len(wiki) >= 1
|
assert len(wiki) >= 1
|
||||||
|
|
||||||
def test_album_wiki_published_date(self) -> None:
|
def test_album_wiki_published_date(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = pylast.Album("Test Artist", "Test Album", self.network)
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
|
@ -61,7 +59,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
assert wiki is not None
|
assert wiki is not None
|
||||||
assert len(wiki) >= 1
|
assert len(wiki) >= 1
|
||||||
|
|
||||||
def test_album_wiki_summary(self) -> None:
|
def test_album_wiki_summary(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = pylast.Album("Test Artist", "Test Album", self.network)
|
album = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
|
||||||
|
@ -72,7 +70,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
assert wiki is not None
|
assert wiki is not None
|
||||||
assert len(wiki) >= 1
|
assert len(wiki) >= 1
|
||||||
|
|
||||||
def test_album_eq_none_is_false(self) -> None:
|
def test_album_eq_none_is_false(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album1 = None
|
album1 = None
|
||||||
album2 = pylast.Album("Test Artist", "Test Album", self.network)
|
album2 = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
@ -80,7 +78,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
assert album1 != album2
|
assert album1 != album2
|
||||||
|
|
||||||
def test_album_ne_none_is_true(self) -> None:
|
def test_album_ne_none_is_true(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album1 = None
|
album1 = None
|
||||||
album2 = pylast.Album("Test Artist", "Test Album", self.network)
|
album2 = pylast.Album("Test Artist", "Test Album", self.network)
|
||||||
|
@ -88,7 +86,7 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
assert album1 != album2
|
assert album1 != album2
|
||||||
|
|
||||||
def test_get_cover_image(self) -> None:
|
def test_get_cover_image(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = self.network.get_album("Test Artist", "Test Album")
|
album = self.network.get_album("Test Artist", "Test Album")
|
||||||
|
|
||||||
|
@ -96,25 +94,5 @@ class TestPyLastAlbum(TestPyLastWithLastFm):
|
||||||
image = album.get_cover_image()
|
image = album.get_cover_image()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert image.startswith("https://")
|
self.assert_startswith(image, "https://")
|
||||||
assert image.endswith(".gif") or image.endswith(".png")
|
self.assert_endswith(image, ".png")
|
||||||
|
|
||||||
def test_mbid(self) -> None:
|
|
||||||
# Arrange
|
|
||||||
album = self.network.get_album("Radiohead", "OK Computer")
|
|
||||||
|
|
||||||
# Act
|
|
||||||
mbid = album.get_mbid()
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
assert mbid == "0b6b4ba0-d36f-47bd-b4ea-6a5b91842d29"
|
|
||||||
|
|
||||||
def test_no_mbid(self) -> None:
|
|
||||||
# Arrange
|
|
||||||
album = self.network.get_album("Test Artist", "Test Album")
|
|
||||||
|
|
||||||
# Act
|
|
||||||
mbid = album.get_mbid()
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
assert mbid is None
|
|
||||||
|
|
|
@ -2,17 +2,14 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
import pytest
|
||||||
|
|
||||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastArtist(TestPyLastWithLastFm):
|
class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
def test_repr(self) -> None:
|
def test_repr(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("Test Artist", self.network)
|
artist = pylast.Artist("Test Artist", self.network)
|
||||||
|
|
||||||
|
@ -22,16 +19,16 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert representation.startswith("pylast.Artist('Test Artist',")
|
assert representation.startswith("pylast.Artist('Test Artist',")
|
||||||
|
|
||||||
def test_artist_is_hashable(self) -> None:
|
def test_artist_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
test_artist = self.network.get_artist("Radiohead")
|
test_artist = self.network.get_artist("Test Artist")
|
||||||
artist = test_artist.get_similar(limit=2)[0].item
|
artist = test_artist.get_similar(limit=2)[0].item
|
||||||
assert isinstance(artist, pylast.Artist)
|
assert isinstance(artist, pylast.Artist)
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_is_thing_hashable(artist)
|
self.helper_is_thing_hashable(artist)
|
||||||
|
|
||||||
def test_bio_published_date(self) -> None:
|
def test_bio_published_date(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("Test Artist", self.network)
|
artist = pylast.Artist("Test Artist", self.network)
|
||||||
|
|
||||||
|
@ -42,7 +39,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
assert bio is not None
|
assert bio is not None
|
||||||
assert len(bio) >= 1
|
assert len(bio) >= 1
|
||||||
|
|
||||||
def test_bio_content(self) -> None:
|
def test_bio_content(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("Test Artist", self.network)
|
artist = pylast.Artist("Test Artist", self.network)
|
||||||
|
|
||||||
|
@ -53,7 +50,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
assert bio is not None
|
assert bio is not None
|
||||||
assert len(bio) >= 1
|
assert len(bio) >= 1
|
||||||
|
|
||||||
def test_bio_content_none(self) -> None:
|
def test_bio_content_none(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# An artist with no biography, with "<content/>" in the API XML
|
# An artist with no biography, with "<content/>" in the API XML
|
||||||
artist = pylast.Artist("Mr Sizef + Unquote", self.network)
|
artist = pylast.Artist("Mr Sizef + Unquote", self.network)
|
||||||
|
@ -64,7 +61,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert bio is None
|
assert bio is None
|
||||||
|
|
||||||
def test_bio_summary(self) -> None:
|
def test_bio_summary(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("Test Artist", self.network)
|
artist = pylast.Artist("Test Artist", self.network)
|
||||||
|
|
||||||
|
@ -75,7 +72,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
assert bio is not None
|
assert bio is not None
|
||||||
assert len(bio) >= 1
|
assert len(bio) >= 1
|
||||||
|
|
||||||
def test_artist_top_tracks(self) -> None:
|
def test_artist_top_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Pick an artist with plenty of plays
|
# Pick an artist with plenty of plays
|
||||||
artist = self.network.get_top_artists(limit=1)[0].item
|
artist = self.network.get_top_artists(limit=1)[0].item
|
||||||
|
@ -86,41 +83,54 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||||
|
|
||||||
def test_artist_top_albums(self) -> None:
|
def test_artist_top_albums(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Pick an artist with plenty of plays
|
# Pick an artist with plenty of plays
|
||||||
artist = self.network.get_top_artists(limit=1)[0].item
|
artist = self.network.get_top_artists(limit=1)[0].item
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
things = list(artist.get_top_albums(limit=2))
|
things = artist.get_top_albums(limit=2)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_two_different_things_in_top_list(things, pylast.Album)
|
self.helper_two_different_things_in_top_list(things, pylast.Album)
|
||||||
|
|
||||||
@pytest.mark.parametrize("test_limit", [1, 50, 100])
|
def test_artist_top_albums_limit_1(self):
|
||||||
def test_artist_top_albums_limit(self, test_limit: int) -> None:
|
|
||||||
# Arrange
|
# Arrange
|
||||||
|
limit = 1
|
||||||
# Pick an artist with plenty of plays
|
# Pick an artist with plenty of plays
|
||||||
artist = self.network.get_top_artists(limit=1)[0].item
|
artist = self.network.get_top_artists(limit=1)[0].item
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
things = artist.get_top_albums(limit=test_limit)
|
things = artist.get_top_albums(limit=limit)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert len(things) == test_limit
|
assert len(things) == 1
|
||||||
|
|
||||||
def test_artist_top_albums_limit_default(self) -> None:
|
def test_artist_top_albums_limit_50(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
limit = 50
|
||||||
# Pick an artist with plenty of plays
|
# Pick an artist with plenty of plays
|
||||||
artist = self.network.get_top_artists(limit=1)[0].item
|
artist = self.network.get_top_artists(limit=1)[0].item
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
things = artist.get_top_albums()
|
things = artist.get_top_albums(limit=limit)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert len(things) == 50
|
assert len(things) == 50
|
||||||
|
|
||||||
def test_artist_listener_count(self) -> None:
|
def test_artist_top_albums_limit_100(self):
|
||||||
|
# Arrange
|
||||||
|
limit = 100
|
||||||
|
# Pick an artist with plenty of plays
|
||||||
|
artist = self.network.get_top_artists(limit=1)[0].item
|
||||||
|
|
||||||
|
# Act
|
||||||
|
things = artist.get_top_albums(limit=limit)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert len(things) == 100
|
||||||
|
|
||||||
|
def test_artist_listener_count(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
|
|
||||||
|
@ -132,7 +142,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
assert count > 0
|
assert count > 0
|
||||||
|
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_tag_artist(self) -> None:
|
def test_tag_artist(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
# artist.clear_tags()
|
# artist.clear_tags()
|
||||||
|
@ -143,11 +153,15 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
tags = artist.get_tags()
|
tags = artist.get_tags()
|
||||||
assert len(tags) > 0
|
assert len(tags) > 0
|
||||||
found = any(tag.name == "testing" for tag in tags)
|
found = False
|
||||||
|
for tag in tags:
|
||||||
|
if tag.name == "testing":
|
||||||
|
found = True
|
||||||
|
break
|
||||||
assert found
|
assert found
|
||||||
|
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_remove_tag_of_type_text(self) -> None:
|
def test_remove_tag_of_type_text(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag = "testing" # text
|
tag = "testing" # text
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
|
@ -158,11 +172,15 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
tags = artist.get_tags()
|
tags = artist.get_tags()
|
||||||
found = any(tag.name == "testing" for tag in tags)
|
found = False
|
||||||
|
for tag in tags:
|
||||||
|
if tag.name == "testing":
|
||||||
|
found = True
|
||||||
|
break
|
||||||
assert not found
|
assert not found
|
||||||
|
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_remove_tag_of_type_tag(self) -> None:
|
def test_remove_tag_of_type_tag(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag = pylast.Tag("testing", self.network) # Tag
|
tag = pylast.Tag("testing", self.network) # Tag
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
|
@ -173,11 +191,15 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
tags = artist.get_tags()
|
tags = artist.get_tags()
|
||||||
found = any(tag.name == "testing" for tag in tags)
|
found = False
|
||||||
|
for tag in tags:
|
||||||
|
if tag.name == "testing":
|
||||||
|
found = True
|
||||||
|
break
|
||||||
assert not found
|
assert not found
|
||||||
|
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_remove_tags(self) -> None:
|
def test_remove_tags(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tags = ["removetag1", "removetag2"]
|
tags = ["removetag1", "removetag2"]
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
|
@ -191,13 +213,17 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
tags_after = artist.get_tags()
|
tags_after = artist.get_tags()
|
||||||
assert len(tags_after) == len(tags_before) - 2
|
assert len(tags_after) == len(tags_before) - 2
|
||||||
found1 = any(tag.name == "removetag1" for tag in tags_after)
|
found1, found2 = False, False
|
||||||
found2 = any(tag.name == "removetag2" for tag in tags_after)
|
for tag in tags_after:
|
||||||
|
if tag.name == "removetag1":
|
||||||
|
found1 = True
|
||||||
|
elif tag.name == "removetag2":
|
||||||
|
found2 = True
|
||||||
assert not found1
|
assert not found1
|
||||||
assert not found2
|
assert not found2
|
||||||
|
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_set_tags(self) -> None:
|
def test_set_tags(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tags = ["sometag1", "sometag2"]
|
tags = ["sometag1", "sometag2"]
|
||||||
artist = self.network.get_artist("Test Artist 2")
|
artist = self.network.get_artist("Test Artist 2")
|
||||||
|
@ -221,7 +247,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
assert found1
|
assert found1
|
||||||
assert found2
|
assert found2
|
||||||
|
|
||||||
def test_artists(self) -> None:
|
def test_artists(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist1 = self.network.get_artist("Radiohead")
|
artist1 = self.network.get_artist("Radiohead")
|
||||||
artist2 = self.network.get_artist("Portishead")
|
artist2 = self.network.get_artist("Portishead")
|
||||||
|
@ -230,18 +256,24 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
url = artist1.get_url()
|
url = artist1.get_url()
|
||||||
mbid = artist1.get_mbid()
|
mbid = artist1.get_mbid()
|
||||||
|
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
|
image = artist1.get_cover_image()
|
||||||
|
|
||||||
playcount = artist1.get_playcount()
|
playcount = artist1.get_playcount()
|
||||||
|
streamable = artist1.is_streamable()
|
||||||
name = artist1.get_name(properly_capitalized=False)
|
name = artist1.get_name(properly_capitalized=False)
|
||||||
name_cap = artist1.get_name(properly_capitalized=True)
|
name_cap = artist1.get_name(properly_capitalized=True)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
|
assert "https" in image
|
||||||
assert playcount > 1
|
assert playcount > 1
|
||||||
assert artist1 != artist2
|
assert artist1 != artist2
|
||||||
assert name.lower() == name_cap.lower()
|
assert name.lower() == name_cap.lower()
|
||||||
assert url == "https://www.last.fm/music/radiohead"
|
assert url == "https://www.last.fm/music/radiohead"
|
||||||
assert mbid == "a74b1b7f-71a5-4011-9441-d0b5e4122711"
|
assert mbid == "a74b1b7f-71a5-4011-9441-d0b5e4122711"
|
||||||
|
assert isinstance(streamable, bool)
|
||||||
|
|
||||||
def test_artist_eq_none_is_false(self) -> None:
|
def test_artist_eq_none_is_false(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist1 = None
|
artist1 = None
|
||||||
artist2 = pylast.Artist("Test Artist", self.network)
|
artist2 = pylast.Artist("Test Artist", self.network)
|
||||||
|
@ -249,7 +281,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
assert artist1 != artist2
|
assert artist1 != artist2
|
||||||
|
|
||||||
def test_artist_ne_none_is_true(self) -> None:
|
def test_artist_ne_none_is_true(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist1 = None
|
artist1 = None
|
||||||
artist2 = pylast.Artist("Test Artist", self.network)
|
artist2 = pylast.Artist("Test Artist", self.network)
|
||||||
|
@ -257,7 +289,7 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
assert artist1 != artist2
|
assert artist1 != artist2
|
||||||
|
|
||||||
def test_artist_get_correction(self) -> None:
|
def test_artist_get_correction(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("guns and roses", self.network)
|
artist = pylast.Artist("guns and roses", self.network)
|
||||||
|
|
||||||
|
@ -267,7 +299,8 @@ class TestPyLastArtist(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert corrected_artist_name == "Guns N' Roses"
|
assert corrected_artist_name == "Guns N' Roses"
|
||||||
|
|
||||||
def test_get_userplaycount(self) -> None:
|
@pytest.mark.xfail
|
||||||
|
def test_get_userplaycount(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("John Lennon", self.network, username=self.username)
|
artist = pylast.Artist("John Lennon", self.network, username=self.username)
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,20 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastCountry(TestPyLastWithLastFm):
|
class TestPyLastCountry(TestPyLastWithLastFm):
|
||||||
def test_country_is_hashable(self) -> None:
|
def test_country_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
country = self.network.get_country("Italy")
|
country = self.network.get_country("Italy")
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_is_thing_hashable(country)
|
self.helper_is_thing_hashable(country)
|
||||||
|
|
||||||
def test_countries(self) -> None:
|
def test_countries(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
country1 = pylast.Country("Italy", self.network)
|
country1 = pylast.Country("Italy", self.network)
|
||||||
country2 = pylast.Country("Finland", self.network)
|
country2 = pylast.Country("Finland", self.network)
|
||||||
|
|
|
@ -2,15 +2,13 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastLibrary(TestPyLastWithLastFm):
|
class TestPyLastLibrary(TestPyLastWithLastFm):
|
||||||
def test_repr(self) -> None:
|
def test_repr(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
library = pylast.Library(user=self.username, network=self.network)
|
library = pylast.Library(user=self.username, network=self.network)
|
||||||
|
|
||||||
|
@ -18,9 +16,9 @@ class TestPyLastLibrary(TestPyLastWithLastFm):
|
||||||
representation = repr(library)
|
representation = repr(library)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert representation.startswith("pylast.Library(")
|
self.assert_startswith(representation, "pylast.Library(")
|
||||||
|
|
||||||
def test_str(self) -> None:
|
def test_str(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
library = pylast.Library(user=self.username, network=self.network)
|
library = pylast.Library(user=self.username, network=self.network)
|
||||||
|
|
||||||
|
@ -28,23 +26,23 @@ class TestPyLastLibrary(TestPyLastWithLastFm):
|
||||||
string = str(library)
|
string = str(library)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert string.endswith("'s Library")
|
self.assert_endswith(string, "'s Library")
|
||||||
|
|
||||||
def test_library_is_hashable(self) -> None:
|
def test_library_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
library = pylast.Library(user=self.username, network=self.network)
|
library = pylast.Library(user=self.username, network=self.network)
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_is_thing_hashable(library)
|
self.helper_is_thing_hashable(library)
|
||||||
|
|
||||||
def test_cacheable_library(self) -> None:
|
def test_cacheable_library(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
library = pylast.Library(self.username, self.network)
|
library = pylast.Library(self.username, self.network)
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_validate_cacheable(library, "get_artists")
|
self.helper_validate_cacheable(library, "get_artists")
|
||||||
|
|
||||||
def test_get_user(self) -> None:
|
def test_get_user(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
library = pylast.Library(user=self.username, network=self.network)
|
library = pylast.Library(user=self.username, network=self.network)
|
||||||
user_to_get = self.network.get_user(self.username)
|
user_to_get = self.network.get_user(self.username)
|
||||||
|
|
|
@ -2,20 +2,17 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
import pylast
|
||||||
|
|
||||||
from flaky import flaky
|
from flaky import flaky
|
||||||
|
|
||||||
import pylast
|
from .test_pylast import PyLastTestCase, load_secrets
|
||||||
|
|
||||||
from .test_pylast import load_secrets
|
|
||||||
|
|
||||||
|
|
||||||
@flaky(max_runs=3, min_passes=1)
|
@flaky(max_runs=3, min_passes=1)
|
||||||
class TestPyLastWithLibreFm:
|
class TestPyLastWithLibreFm(PyLastTestCase):
|
||||||
"""Own class for Libre.fm because we don't need the Last.fm setUp"""
|
"""Own class for Libre.fm because we don't need the Last.fm setUp"""
|
||||||
|
|
||||||
def test_libre_fm(self) -> None:
|
def test_libre_fm(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
secrets = load_secrets()
|
secrets = load_secrets()
|
||||||
username = secrets["username"]
|
username = secrets["username"]
|
||||||
|
@ -29,7 +26,7 @@ class TestPyLastWithLibreFm:
|
||||||
# Assert
|
# Assert
|
||||||
assert name == "Radiohead"
|
assert name == "Radiohead"
|
||||||
|
|
||||||
def test_repr(self) -> None:
|
def test_repr(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
secrets = load_secrets()
|
secrets = load_secrets()
|
||||||
username = secrets["username"]
|
username = secrets["username"]
|
||||||
|
@ -40,4 +37,4 @@ class TestPyLastWithLibreFm:
|
||||||
representation = repr(network)
|
representation = repr(network)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert representation.startswith("pylast.LibreFMNetwork(")
|
self.assert_startswith(representation, "pylast.LibreFMNetwork(")
|
||||||
|
|
|
@ -1,22 +1,19 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
import pytest
|
||||||
|
|
||||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastNetwork(TestPyLastWithLastFm):
|
class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_scrobble(self) -> None:
|
def test_scrobble(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "test artist"
|
artist = "test artist"
|
||||||
title = "test title"
|
title = "test title"
|
||||||
|
@ -29,12 +26,12 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
# limit=2 to ignore now-playing:
|
# limit=2 to ignore now-playing:
|
||||||
last_scrobble = list(lastfm_user.get_recent_tracks(limit=2))[0]
|
last_scrobble = lastfm_user.get_recent_tracks(limit=2)[0]
|
||||||
assert str(last_scrobble.track.artist).lower() == artist
|
assert str(last_scrobble.track.artist).lower() == artist
|
||||||
assert str(last_scrobble.track.title).lower() == title
|
assert str(last_scrobble.track.title).lower() == title
|
||||||
|
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_update_now_playing(self) -> None:
|
def test_update_now_playing(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Test Artist"
|
artist = "Test Artist"
|
||||||
title = "test title"
|
title = "test title"
|
||||||
|
@ -58,7 +55,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert len(current_track.info["image"])
|
assert len(current_track.info["image"])
|
||||||
assert re.search(r"^http.+$", current_track.info["image"][pylast.SIZE_LARGE])
|
assert re.search(r"^http.+$", current_track.info["image"][pylast.SIZE_LARGE])
|
||||||
|
|
||||||
def test_enable_rate_limiting(self) -> None:
|
def test_enable_rate_limiting(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
assert not self.network.is_rate_limited()
|
assert not self.network.is_rate_limited()
|
||||||
|
|
||||||
|
@ -66,7 +63,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
self.network.enable_rate_limit()
|
self.network.enable_rate_limit()
|
||||||
then = time.time()
|
then = time.time()
|
||||||
# Make some network call, limit not applied first time
|
# Make some network call, limit not applied first time
|
||||||
self.network.get_top_artists()
|
self.network.get_user(self.username)
|
||||||
# Make a second network call, limiting should be applied
|
# Make a second network call, limiting should be applied
|
||||||
self.network.get_top_artists()
|
self.network.get_top_artists()
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
@ -75,7 +72,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert self.network.is_rate_limited()
|
assert self.network.is_rate_limited()
|
||||||
assert now - then >= 0.2
|
assert now - then >= 0.2
|
||||||
|
|
||||||
def test_disable_rate_limiting(self) -> None:
|
def test_disable_rate_limiting(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
self.network.enable_rate_limit()
|
self.network.enable_rate_limit()
|
||||||
assert self.network.is_rate_limited()
|
assert self.network.is_rate_limited()
|
||||||
|
@ -90,14 +87,14 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert not self.network.is_rate_limited()
|
assert not self.network.is_rate_limited()
|
||||||
|
|
||||||
def test_lastfm_network_name(self) -> None:
|
def test_lastfm_network_name(self):
|
||||||
# Act
|
# Act
|
||||||
name = str(self.network)
|
name = str(self.network)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert name == "Last.fm Network"
|
assert name == "Last.fm Network"
|
||||||
|
|
||||||
def test_geo_get_top_artists(self) -> None:
|
def test_geo_get_top_artists(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
artists = self.network.get_geo_top_artists(country="United Kingdom", limit=1)
|
artists = self.network.get_geo_top_artists(country="United Kingdom", limit=1)
|
||||||
|
@ -107,7 +104,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert isinstance(artists[0], pylast.TopItem)
|
assert isinstance(artists[0], pylast.TopItem)
|
||||||
assert isinstance(artists[0].item, pylast.Artist)
|
assert isinstance(artists[0].item, pylast.Artist)
|
||||||
|
|
||||||
def test_geo_get_top_tracks(self) -> None:
|
def test_geo_get_top_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
tracks = self.network.get_geo_top_tracks(
|
tracks = self.network.get_geo_top_tracks(
|
||||||
|
@ -119,7 +116,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert isinstance(tracks[0], pylast.TopItem)
|
assert isinstance(tracks[0], pylast.TopItem)
|
||||||
assert isinstance(tracks[0].item, pylast.Track)
|
assert isinstance(tracks[0].item, pylast.Track)
|
||||||
|
|
||||||
def test_network_get_top_artists_with_limit(self) -> None:
|
def test_network_get_top_artists_with_limit(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
artists = self.network.get_top_artists(limit=1)
|
artists = self.network.get_top_artists(limit=1)
|
||||||
|
@ -127,7 +124,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
||||||
|
|
||||||
def test_network_get_top_tags_with_limit(self) -> None:
|
def test_network_get_top_tags_with_limit(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
tags = self.network.get_top_tags(limit=1)
|
tags = self.network.get_top_tags(limit=1)
|
||||||
|
@ -135,7 +132,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
|
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
|
||||||
|
|
||||||
def test_network_get_top_tags_with_no_limit(self) -> None:
|
def test_network_get_top_tags_with_no_limit(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
tags = self.network.get_top_tags()
|
tags = self.network.get_top_tags()
|
||||||
|
@ -143,7 +140,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_at_least_one_thing_in_top_list(tags, pylast.Tag)
|
self.helper_at_least_one_thing_in_top_list(tags, pylast.Tag)
|
||||||
|
|
||||||
def test_network_get_top_tracks_with_limit(self) -> None:
|
def test_network_get_top_tracks_with_limit(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
tracks = self.network.get_top_tracks(limit=1)
|
tracks = self.network.get_top_tracks(limit=1)
|
||||||
|
@ -151,7 +148,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(tracks, pylast.Track)
|
self.helper_only_one_thing_in_top_list(tracks, pylast.Track)
|
||||||
|
|
||||||
def test_country_top_tracks(self) -> None:
|
def test_country_top_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
country = self.network.get_country("Croatia")
|
country = self.network.get_country("Croatia")
|
||||||
|
|
||||||
|
@ -161,7 +158,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||||
|
|
||||||
def test_country_network_top_tracks(self) -> None:
|
def test_country_network_top_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Act
|
# Act
|
||||||
things = self.network.get_geo_top_tracks("Croatia", limit=2)
|
things = self.network.get_geo_top_tracks("Croatia", limit=2)
|
||||||
|
@ -169,7 +166,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||||
|
|
||||||
def test_tag_top_tracks(self) -> None:
|
def test_tag_top_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag = self.network.get_tag("blues")
|
tag = self.network.get_tag("blues")
|
||||||
|
|
||||||
|
@ -179,7 +176,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||||
|
|
||||||
def test_album_data(self) -> None:
|
def test_album_data(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
thing = self.network.get_album("Test Artist", "Test Album")
|
thing = self.network.get_album("Test Artist", "Test Album")
|
||||||
|
|
||||||
|
@ -199,7 +196,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert playcount > 1
|
assert playcount > 1
|
||||||
assert "https://www.last.fm/music/test%2bartist/test%2balbum" == url
|
assert "https://www.last.fm/music/test%2bartist/test%2balbum" == url
|
||||||
|
|
||||||
def test_track_data(self) -> None:
|
def test_track_data(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
thing = self.network.get_track("Test Artist", "test title")
|
thing = self.network.get_track("Test Artist", "test title")
|
||||||
|
|
||||||
|
@ -220,7 +217,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert playcount > 1
|
assert playcount > 1
|
||||||
assert "https://www.last.fm/fr/music/test%2bartist/_/test%2btitle" == url
|
assert "https://www.last.fm/fr/music/test%2bartist/_/test%2btitle" == url
|
||||||
|
|
||||||
def test_country_top_artists(self) -> None:
|
def test_country_top_artists(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
country = self.network.get_country("Ukraine")
|
country = self.network.get_country("Ukraine")
|
||||||
|
|
||||||
|
@ -230,7 +227,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
||||||
|
|
||||||
def test_caching(self) -> None:
|
def test_caching(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -245,9 +242,9 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
self.network.disable_caching()
|
self.network.disable_caching()
|
||||||
assert not self.network.is_caching_enabled()
|
assert not self.network.is_caching_enabled()
|
||||||
|
|
||||||
def test_album_mbid(self) -> None:
|
def test_album_mbid(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
mbid = "03c91c40-49a6-44a7-90e7-a700edf97a62"
|
mbid = "a6a265bf-9f81-4055-8224-f7ac0aa6b937"
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
album = self.network.get_album_by_mbid(mbid)
|
album = self.network.get_album_by_mbid(mbid)
|
||||||
|
@ -255,10 +252,10 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert isinstance(album, pylast.Album)
|
assert isinstance(album, pylast.Album)
|
||||||
assert album.title == "Believe"
|
assert album.title.lower() == "test"
|
||||||
assert album_mbid == mbid
|
assert album_mbid == mbid
|
||||||
|
|
||||||
def test_artist_mbid(self) -> None:
|
def test_artist_mbid(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
mbid = "7e84f845-ac16-41fe-9ff8-df12eb32af55"
|
mbid = "7e84f845-ac16-41fe-9ff8-df12eb32af55"
|
||||||
|
|
||||||
|
@ -267,9 +264,9 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert isinstance(artist, pylast.Artist)
|
assert isinstance(artist, pylast.Artist)
|
||||||
assert artist.name in ("MusicBrainz Test Artist", "MusicBrainzz Test Artist")
|
assert artist.name == "MusicBrainz Test Artist"
|
||||||
|
|
||||||
def test_track_mbid(self) -> None:
|
def test_track_mbid(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
mbid = "ebc037b1-cc9c-44f2-a21f-83c219f0e1e0"
|
mbid = "ebc037b1-cc9c-44f2-a21f-83c219f0e1e0"
|
||||||
|
|
||||||
|
@ -282,7 +279,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert track.title == "first"
|
assert track.title == "first"
|
||||||
assert track_mbid == mbid
|
assert track_mbid == mbid
|
||||||
|
|
||||||
def test_init_with_token(self) -> None:
|
def test_init_with_token(self):
|
||||||
# Arrange/Act
|
# Arrange/Act
|
||||||
msg = None
|
msg = None
|
||||||
try:
|
try:
|
||||||
|
@ -297,19 +294,20 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert msg == "Unauthorized Token - This token has not been issued"
|
assert msg == "Unauthorized Token - This token has not been issued"
|
||||||
|
|
||||||
def test_proxy(self) -> None:
|
def test_proxy(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
proxy = "http://example.com:1234"
|
host = "https://example.com"
|
||||||
|
port = 1234
|
||||||
|
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
self.network.enable_proxy(proxy)
|
self.network.enable_proxy(host, port)
|
||||||
assert self.network.is_proxy_enabled()
|
assert self.network.is_proxy_enabled()
|
||||||
assert self.network.proxy == "http://example.com:1234"
|
assert self.network._get_proxy() == ["https://example.com", 1234]
|
||||||
|
|
||||||
self.network.disable_proxy()
|
self.network.disable_proxy()
|
||||||
assert not self.network.is_proxy_enabled()
|
assert not self.network.is_proxy_enabled()
|
||||||
|
|
||||||
def test_album_search(self) -> None:
|
def test_album_search(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = "Nevermind"
|
album = "Nevermind"
|
||||||
|
|
||||||
|
@ -321,7 +319,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert isinstance(results, list)
|
assert isinstance(results, list)
|
||||||
assert isinstance(results[0], pylast.Album)
|
assert isinstance(results[0], pylast.Album)
|
||||||
|
|
||||||
def test_album_search_images(self) -> None:
|
def test_album_search_images(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = "Nevermind"
|
album = "Nevermind"
|
||||||
search = self.network.search_for_album(album)
|
search = self.network.search_for_album(album)
|
||||||
|
@ -333,15 +331,15 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert len(images) == 4
|
assert len(images) == 4
|
||||||
|
|
||||||
assert images[pylast.SIZE_SMALL].startswith("https://")
|
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
|
||||||
assert images[pylast.SIZE_SMALL].endswith(".png")
|
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
|
||||||
assert "/34s/" in images[pylast.SIZE_SMALL]
|
assert "/34s/" in images[pylast.SIZE_SMALL]
|
||||||
|
|
||||||
assert images[pylast.SIZE_EXTRA_LARGE].startswith("https://")
|
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
|
||||||
assert images[pylast.SIZE_EXTRA_LARGE].endswith(".png")
|
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
|
||||||
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
|
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
|
||||||
|
|
||||||
def test_artist_search(self) -> None:
|
def test_artist_search(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Nirvana"
|
artist = "Nirvana"
|
||||||
|
|
||||||
|
@ -353,7 +351,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert isinstance(results, list)
|
assert isinstance(results, list)
|
||||||
assert isinstance(results[0], pylast.Artist)
|
assert isinstance(results[0], pylast.Artist)
|
||||||
|
|
||||||
def test_artist_search_images(self) -> None:
|
def test_artist_search_images(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Nirvana"
|
artist = "Nirvana"
|
||||||
search = self.network.search_for_artist(artist)
|
search = self.network.search_for_artist(artist)
|
||||||
|
@ -365,15 +363,15 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert len(images) == 5
|
assert len(images) == 5
|
||||||
|
|
||||||
assert images[pylast.SIZE_SMALL].startswith("https://")
|
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
|
||||||
assert images[pylast.SIZE_SMALL].endswith(".png")
|
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
|
||||||
assert "/34s/" in images[pylast.SIZE_SMALL]
|
assert "/34s/" in images[pylast.SIZE_SMALL]
|
||||||
|
|
||||||
assert images[pylast.SIZE_EXTRA_LARGE].startswith("https://")
|
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
|
||||||
assert images[pylast.SIZE_EXTRA_LARGE].endswith(".png")
|
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
|
||||||
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
|
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
|
||||||
|
|
||||||
def test_track_search(self) -> None:
|
def test_track_search(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Nirvana"
|
artist = "Nirvana"
|
||||||
track = "Smells Like Teen Spirit"
|
track = "Smells Like Teen Spirit"
|
||||||
|
@ -386,7 +384,7 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
assert isinstance(results, list)
|
assert isinstance(results, list)
|
||||||
assert isinstance(results[0], pylast.Track)
|
assert isinstance(results[0], pylast.Track)
|
||||||
|
|
||||||
def test_track_search_images(self) -> None:
|
def test_track_search_images(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Nirvana"
|
artist = "Nirvana"
|
||||||
track = "Smells Like Teen Spirit"
|
track = "Smells Like Teen Spirit"
|
||||||
|
@ -399,15 +397,15 @@ class TestPyLastNetwork(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert len(images) == 4
|
assert len(images) == 4
|
||||||
|
|
||||||
assert images[pylast.SIZE_SMALL].startswith("https://")
|
self.assert_startswith(images[pylast.SIZE_SMALL], "https://")
|
||||||
assert images[pylast.SIZE_SMALL].endswith(".png")
|
self.assert_endswith(images[pylast.SIZE_SMALL], ".png")
|
||||||
assert "/34s/" in images[pylast.SIZE_SMALL]
|
assert "/34s/" in images[pylast.SIZE_SMALL]
|
||||||
|
|
||||||
assert images[pylast.SIZE_EXTRA_LARGE].startswith("https://")
|
self.assert_startswith(images[pylast.SIZE_EXTRA_LARGE], "https://")
|
||||||
assert images[pylast.SIZE_EXTRA_LARGE].endswith(".png")
|
self.assert_endswith(images[pylast.SIZE_EXTRA_LARGE], ".png")
|
||||||
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
|
assert "/300x300/" in images[pylast.SIZE_EXTRA_LARGE]
|
||||||
|
|
||||||
def test_search_get_total_result_count(self) -> None:
|
def test_search_get_total_result_count(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Nirvana"
|
artist = "Nirvana"
|
||||||
track = "Smells Like Teen Spirit"
|
track = "Smells Like Teen Spirit"
|
||||||
|
|
|
@ -2,20 +2,18 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import pylast
|
||||||
import pytest
|
import pytest
|
||||||
from flaky import flaky
|
from flaky import flaky
|
||||||
|
|
||||||
import pylast
|
WRITE_TEST = sys.version_info[:2] == (3, 8)
|
||||||
|
|
||||||
WRITE_TEST = False
|
|
||||||
|
|
||||||
|
|
||||||
def load_secrets(): # pragma: no cover
|
def load_secrets():
|
||||||
secrets_file = "test_pylast.yaml"
|
secrets_file = "test_pylast.yaml"
|
||||||
if os.path.isfile(secrets_file):
|
if os.path.isfile(secrets_file):
|
||||||
import yaml # pip install pyyaml
|
import yaml # pip install pyyaml
|
||||||
|
@ -34,21 +32,24 @@ def load_secrets(): # pragma: no cover
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
||||||
def _no_xfail_rerun_filter(err, name, test, plugin) -> bool:
|
class PyLastTestCase:
|
||||||
for _ in test.iter_markers(name="xfail"):
|
def assert_startswith(self, str, prefix, start=None, end=None):
|
||||||
return False
|
assert str.startswith(prefix, start, end)
|
||||||
|
|
||||||
|
def assert_endswith(self, str, suffix, start=None, end=None):
|
||||||
|
assert str.endswith(suffix, start, end)
|
||||||
|
|
||||||
|
|
||||||
@flaky(max_runs=3, min_passes=1, rerun_filter=_no_xfail_rerun_filter)
|
@flaky(max_runs=3, min_passes=1)
|
||||||
class TestPyLastWithLastFm:
|
class TestPyLastWithLastFm(PyLastTestCase):
|
||||||
|
|
||||||
secrets = None
|
secrets = None
|
||||||
|
|
||||||
@staticmethod
|
def unix_timestamp(self):
|
||||||
def unix_timestamp() -> int:
|
|
||||||
return int(time.time())
|
return int(time.time())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_class(cls) -> None:
|
def setup_class(cls):
|
||||||
if cls.secrets is None:
|
if cls.secrets is None:
|
||||||
cls.secrets = load_secrets()
|
cls.secrets = load_secrets()
|
||||||
|
|
||||||
|
@ -65,8 +66,7 @@ class TestPyLastWithLastFm:
|
||||||
password_hash=password_hash,
|
password_hash=password_hash,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
def helper_is_thing_hashable(self, thing):
|
||||||
def helper_is_thing_hashable(thing) -> None:
|
|
||||||
# Arrange
|
# Arrange
|
||||||
things = set()
|
things = set()
|
||||||
|
|
||||||
|
@ -77,19 +77,18 @@ class TestPyLastWithLastFm:
|
||||||
assert thing is not None
|
assert thing is not None
|
||||||
assert len(things) == 1
|
assert len(things) == 1
|
||||||
|
|
||||||
@staticmethod
|
def helper_validate_results(self, a, b, c):
|
||||||
def helper_validate_results(a, b, c) -> None:
|
|
||||||
# Assert
|
# Assert
|
||||||
assert a is not None
|
assert a is not None
|
||||||
assert b is not None
|
assert b is not None
|
||||||
assert c is not None
|
assert c is not None
|
||||||
assert isinstance(len(a), int)
|
assert len(a) >= 0
|
||||||
assert isinstance(len(b), int)
|
assert len(b) >= 0
|
||||||
assert isinstance(len(c), int)
|
assert len(c) >= 0
|
||||||
assert a == b
|
assert a == b
|
||||||
assert b == c
|
assert b == c
|
||||||
|
|
||||||
def helper_validate_cacheable(self, thing, function_name) -> None:
|
def helper_validate_cacheable(self, thing, function_name):
|
||||||
# Arrange
|
# Arrange
|
||||||
# get thing.function_name()
|
# get thing.function_name()
|
||||||
func = getattr(thing, function_name, None)
|
func = getattr(thing, function_name, None)
|
||||||
|
@ -97,36 +96,32 @@ class TestPyLastWithLastFm:
|
||||||
# Act
|
# Act
|
||||||
result1 = func(limit=1, cacheable=False)
|
result1 = func(limit=1, cacheable=False)
|
||||||
result2 = func(limit=1, cacheable=True)
|
result2 = func(limit=1, cacheable=True)
|
||||||
result3 = list(func(limit=1))
|
result3 = func(limit=1)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_validate_results(result1, result2, result3)
|
self.helper_validate_results(result1, result2, result3)
|
||||||
|
|
||||||
@staticmethod
|
def helper_at_least_one_thing_in_top_list(self, things, expected_type):
|
||||||
def helper_at_least_one_thing_in_top_list(things, expected_type) -> None:
|
|
||||||
# Assert
|
# Assert
|
||||||
assert len(things) > 1
|
assert len(things) > 1
|
||||||
assert isinstance(things, list)
|
assert isinstance(things, list)
|
||||||
assert isinstance(things[0], pylast.TopItem)
|
assert isinstance(things[0], pylast.TopItem)
|
||||||
assert isinstance(things[0].item, expected_type)
|
assert isinstance(things[0].item, expected_type)
|
||||||
|
|
||||||
@staticmethod
|
def helper_only_one_thing_in_top_list(self, things, expected_type):
|
||||||
def helper_only_one_thing_in_top_list(things, expected_type) -> None:
|
|
||||||
# Assert
|
# Assert
|
||||||
assert len(things) == 1
|
assert len(things) == 1
|
||||||
assert isinstance(things, list)
|
assert isinstance(things, list)
|
||||||
assert isinstance(things[0], pylast.TopItem)
|
assert isinstance(things[0], pylast.TopItem)
|
||||||
assert isinstance(things[0].item, expected_type)
|
assert isinstance(things[0].item, expected_type)
|
||||||
|
|
||||||
@staticmethod
|
def helper_only_one_thing_in_list(self, things, expected_type):
|
||||||
def helper_only_one_thing_in_list(things, expected_type) -> None:
|
|
||||||
# Assert
|
# Assert
|
||||||
assert len(things) == 1
|
assert len(things) == 1
|
||||||
assert isinstance(things, list)
|
assert isinstance(things, list)
|
||||||
assert isinstance(things[0], expected_type)
|
assert isinstance(things[0], expected_type)
|
||||||
|
|
||||||
@staticmethod
|
def helper_two_different_things_in_top_list(self, things, expected_type):
|
||||||
def helper_two_different_things_in_top_list(things, expected_type) -> None:
|
|
||||||
# Assert
|
# Assert
|
||||||
assert len(things) == 2
|
assert len(things) == 2
|
||||||
thing1 = things[0]
|
thing1 = things[0]
|
||||||
|
|
|
@ -2,22 +2,20 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastTag(TestPyLastWithLastFm):
|
class TestPyLastTag(TestPyLastWithLastFm):
|
||||||
def test_tag_is_hashable(self) -> None:
|
def test_tag_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag = self.network.get_top_tags(limit=1)[0]
|
tag = self.network.get_top_tags(limit=1)[0]
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_is_thing_hashable(tag)
|
self.helper_is_thing_hashable(tag)
|
||||||
|
|
||||||
def test_tag_top_artists(self) -> None:
|
def test_tag_top_artists(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag = self.network.get_tag("blues")
|
tag = self.network.get_tag("blues")
|
||||||
|
|
||||||
|
@ -27,7 +25,7 @@ class TestPyLastTag(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
||||||
|
|
||||||
def test_tag_top_albums(self) -> None:
|
def test_tag_top_albums(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag = self.network.get_tag("blues")
|
tag = self.network.get_tag("blues")
|
||||||
|
|
||||||
|
@ -37,7 +35,7 @@ class TestPyLastTag(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(albums, pylast.Album)
|
self.helper_only_one_thing_in_top_list(albums, pylast.Album)
|
||||||
|
|
||||||
def test_tags(self) -> None:
|
def test_tags(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
tag1 = self.network.get_tag("blues")
|
tag1 = self.network.get_tag("blues")
|
||||||
tag2 = self.network.get_tag("rock")
|
tag2 = self.network.get_tag("rock")
|
||||||
|
|
|
@ -1,21 +1,18 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
import pytest
|
||||||
|
|
||||||
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
from .test_pylast import WRITE_TEST, TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastTrack(TestPyLastWithLastFm):
|
class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_love(self) -> None:
|
def test_love(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Test Artist"
|
artist = "Test Artist"
|
||||||
title = "test title"
|
title = "test title"
|
||||||
|
@ -26,12 +23,12 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
track.love()
|
track.love()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
loved = list(lastfm_user.get_loved_tracks(limit=1))
|
loved = lastfm_user.get_loved_tracks(limit=1)
|
||||||
assert str(loved[0].track.artist).lower() == "test artist"
|
assert str(loved[0].track.artist).lower() == "test artist"
|
||||||
assert str(loved[0].track.title).lower() == "test title"
|
assert str(loved[0].track.title).lower() == "test title"
|
||||||
|
|
||||||
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
@pytest.mark.skipif(not WRITE_TEST, reason="Only test once to avoid collisions")
|
||||||
def test_unlove(self) -> None:
|
def test_unlove(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = pylast.Artist("Test Artist", self.network)
|
artist = pylast.Artist("Test Artist", self.network)
|
||||||
title = "test title"
|
title = "test title"
|
||||||
|
@ -44,12 +41,12 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
time.sleep(1) # Delay, for Last.fm latency. TODO Can this be removed later?
|
time.sleep(1) # Delay, for Last.fm latency. TODO Can this be removed later?
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
loved = list(lastfm_user.get_loved_tracks(limit=1))
|
loved = lastfm_user.get_loved_tracks(limit=1)
|
||||||
if len(loved): # OK to be empty but if not:
|
if len(loved): # OK to be empty but if not:
|
||||||
assert str(loved[0].track.artist) != "Test Artist"
|
assert str(loved[0].track.artist) != "Test Artist"
|
||||||
assert str(loved[0].track.title) != "test title"
|
assert str(loved[0].track.title) != "test title"
|
||||||
|
|
||||||
def test_user_play_count_in_track_info(self) -> None:
|
def test_user_play_count_in_track_info(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Test Artist"
|
artist = "Test Artist"
|
||||||
title = "test title"
|
title = "test title"
|
||||||
|
@ -63,7 +60,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert count >= 0
|
assert count >= 0
|
||||||
|
|
||||||
def test_user_loved_in_track_info(self) -> None:
|
def test_user_loved_in_track_info(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "Test Artist"
|
artist = "Test Artist"
|
||||||
title = "test title"
|
title = "test title"
|
||||||
|
@ -79,16 +76,16 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
assert isinstance(loved, bool)
|
assert isinstance(loved, bool)
|
||||||
assert not isinstance(loved, str)
|
assert not isinstance(loved, str)
|
||||||
|
|
||||||
def test_track_is_hashable(self) -> None:
|
def test_track_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = self.network.get_artist("Test Artist")
|
artist = self.network.get_artist("Test Artist")
|
||||||
track = artist.get_top_tracks(stream=False)[0].item
|
track = artist.get_top_tracks()[0].item
|
||||||
assert isinstance(track, pylast.Track)
|
assert isinstance(track, pylast.Track)
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_is_thing_hashable(track)
|
self.helper_is_thing_hashable(track)
|
||||||
|
|
||||||
def test_track_wiki_content(self) -> None:
|
def test_track_wiki_content(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Test Artist", "test title", self.network)
|
track = pylast.Track("Test Artist", "test title", self.network)
|
||||||
|
|
||||||
|
@ -99,7 +96,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
assert wiki is not None
|
assert wiki is not None
|
||||||
assert len(wiki) >= 1
|
assert len(wiki) >= 1
|
||||||
|
|
||||||
def test_track_wiki_summary(self) -> None:
|
def test_track_wiki_summary(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Test Artist", "test title", self.network)
|
track = pylast.Track("Test Artist", "test title", self.network)
|
||||||
|
|
||||||
|
@ -110,17 +107,37 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
assert wiki is not None
|
assert wiki is not None
|
||||||
assert len(wiki) >= 1
|
assert len(wiki) >= 1
|
||||||
|
|
||||||
def test_track_get_duration(self) -> None:
|
def test_track_get_duration(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Daft Punk", "Something About Us", self.network)
|
track = pylast.Track("Nirvana", "Lithium", self.network)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
duration = track.get_duration()
|
duration = track.get_duration()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert duration >= 100000
|
assert duration >= 200000
|
||||||
|
|
||||||
def test_track_get_album(self) -> None:
|
def test_track_is_streamable(self):
|
||||||
|
# Arrange
|
||||||
|
track = pylast.Track("Nirvana", "Lithium", self.network)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
streamable = track.is_streamable()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert not streamable
|
||||||
|
|
||||||
|
def test_track_is_fulltrack_available(self):
|
||||||
|
# Arrange
|
||||||
|
track = pylast.Track("Nirvana", "Lithium", self.network)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
fulltrack_available = track.is_fulltrack_available()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
assert not fulltrack_available
|
||||||
|
|
||||||
|
def test_track_get_album(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Nirvana", "Lithium", self.network)
|
track = pylast.Track("Nirvana", "Lithium", self.network)
|
||||||
|
|
||||||
|
@ -130,7 +147,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert str(album) == "Nirvana - Nevermind"
|
assert str(album) == "Nirvana - Nevermind"
|
||||||
|
|
||||||
def test_track_get_similar(self) -> None:
|
def test_track_get_similar(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Cher", "Believe", self.network)
|
track = pylast.Track("Cher", "Believe", self.network)
|
||||||
|
|
||||||
|
@ -138,10 +155,14 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
similar = track.get_similar()
|
similar = track.get_similar()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
found = any(str(track.item) == "Cher - Strong Enough" for track in similar)
|
found = False
|
||||||
|
for track in similar:
|
||||||
|
if str(track.item) == "Madonna - Vogue":
|
||||||
|
found = True
|
||||||
|
break
|
||||||
assert found
|
assert found
|
||||||
|
|
||||||
def test_track_get_similar_limits(self) -> None:
|
def test_track_get_similar_limits(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Cher", "Believe", self.network)
|
track = pylast.Track("Cher", "Believe", self.network)
|
||||||
|
|
||||||
|
@ -151,7 +172,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
assert len(track.get_similar(limit=None)) >= 23
|
assert len(track.get_similar(limit=None)) >= 23
|
||||||
assert len(track.get_similar(limit=0)) >= 23
|
assert len(track.get_similar(limit=0)) >= 23
|
||||||
|
|
||||||
def test_tracks_notequal(self) -> None:
|
def test_tracks_notequal(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track1 = pylast.Track("Test Artist", "test title", self.network)
|
track1 = pylast.Track("Test Artist", "test title", self.network)
|
||||||
track2 = pylast.Track("Test Artist", "Test Track", self.network)
|
track2 = pylast.Track("Test Artist", "Test Track", self.network)
|
||||||
|
@ -160,7 +181,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert track1 != track2
|
assert track1 != track2
|
||||||
|
|
||||||
def test_track_title_prop_caps(self) -> None:
|
def test_track_title_prop_caps(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("test artist", "test title", self.network)
|
track = pylast.Track("test artist", "test title", self.network)
|
||||||
|
|
||||||
|
@ -170,7 +191,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert title == "Test Title"
|
assert title == "Test Title"
|
||||||
|
|
||||||
def test_track_listener_count(self) -> None:
|
def test_track_listener_count(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("test artist", "test title", self.network)
|
track = pylast.Track("test artist", "test title", self.network)
|
||||||
|
|
||||||
|
@ -180,7 +201,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert count > 21
|
assert count > 21
|
||||||
|
|
||||||
def test_album_tracks(self) -> None:
|
def test_album_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
album = pylast.Album("Test Artist", "Test", self.network)
|
album = pylast.Album("Test Artist", "Test", self.network)
|
||||||
|
|
||||||
|
@ -194,7 +215,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
assert len(tracks) == 1
|
assert len(tracks) == 1
|
||||||
assert url.startswith("https://www.last.fm/music/test")
|
assert url.startswith("https://www.last.fm/music/test")
|
||||||
|
|
||||||
def test_track_eq_none_is_false(self) -> None:
|
def test_track_eq_none_is_false(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track1 = None
|
track1 = None
|
||||||
track2 = pylast.Track("Test Artist", "test title", self.network)
|
track2 = pylast.Track("Test Artist", "test title", self.network)
|
||||||
|
@ -202,7 +223,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
assert track1 != track2
|
assert track1 != track2
|
||||||
|
|
||||||
def test_track_ne_none_is_true(self) -> None:
|
def test_track_ne_none_is_true(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track1 = None
|
track1 = None
|
||||||
track2 = pylast.Track("Test Artist", "test title", self.network)
|
track2 = pylast.Track("Test Artist", "test title", self.network)
|
||||||
|
@ -210,7 +231,7 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
assert track1 != track2
|
assert track1 != track2
|
||||||
|
|
||||||
def test_track_get_correction(self) -> None:
|
def test_track_get_correction(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Guns N' Roses", "mrbrownstone", self.network)
|
track = pylast.Track("Guns N' Roses", "mrbrownstone", self.network)
|
||||||
|
|
||||||
|
@ -220,9 +241,16 @@ class TestPyLastTrack(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert corrected_track_name == "Mr. Brownstone"
|
assert corrected_track_name == "Mr. Brownstone"
|
||||||
|
|
||||||
def test_track_with_no_mbid(self) -> None:
|
@pytest.mark.parametrize(
|
||||||
|
("test_artist", "test_track"),
|
||||||
|
[
|
||||||
|
("Static-X", "Set It Off"), # Track with no MBID
|
||||||
|
("Zytaris", "Shores of Life"), # "Track not found"
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_track_with_no_mbid(self, test_artist, test_track):
|
||||||
# Arrange
|
# Arrange
|
||||||
track = pylast.Track("Static-X", "Set It Off", self.network)
|
track = pylast.Track(test_track, test_artist, self.network)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
mbid = track.get_mbid()
|
mbid = track.get_mbid()
|
||||||
|
|
|
@ -2,23 +2,20 @@
|
||||||
"""
|
"""
|
||||||
Integration (not unit) tests for pylast.py
|
Integration (not unit) tests for pylast.py
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
import inspect
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import warnings
|
||||||
import pytest
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
import pytest
|
||||||
|
|
||||||
from .test_pylast import TestPyLastWithLastFm
|
from .test_pylast import TestPyLastWithLastFm
|
||||||
|
|
||||||
|
|
||||||
class TestPyLastUser(TestPyLastWithLastFm):
|
class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
def test_repr(self) -> None:
|
def test_repr(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -26,9 +23,9 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
representation = repr(user)
|
representation = repr(user)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert representation.startswith("pylast.User('RJ',")
|
self.assert_startswith(representation, "pylast.User('RJ',")
|
||||||
|
|
||||||
def test_str(self) -> None:
|
def test_str(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -38,7 +35,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert string == "RJ"
|
assert string == "RJ"
|
||||||
|
|
||||||
def test_equality(self) -> None:
|
def test_equality(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user_1a = self.network.get_user("RJ")
|
user_1a = self.network.get_user("RJ")
|
||||||
user_1b = self.network.get_user("RJ")
|
user_1b = self.network.get_user("RJ")
|
||||||
|
@ -50,7 +47,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert user_1a != user_2
|
assert user_1a != user_2
|
||||||
assert user_1a != not_a_user
|
assert user_1a != not_a_user
|
||||||
|
|
||||||
def test_get_name(self) -> None:
|
def test_get_name(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -60,7 +57,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert name == "RJ"
|
assert name == "RJ"
|
||||||
|
|
||||||
def test_get_user_registration(self) -> None:
|
def test_get_user_registration(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -71,12 +68,12 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
if int(registered):
|
if int(registered):
|
||||||
# Last.fm API broken? Used to be yyyy-mm-dd not Unix timestamp
|
# Last.fm API broken? Used to be yyyy-mm-dd not Unix timestamp
|
||||||
assert registered == "1037793040"
|
assert registered == "1037793040"
|
||||||
else: # pragma: no cover
|
else:
|
||||||
# Old way
|
# Old way
|
||||||
# Just check date because of timezones
|
# Just check date because of timezones
|
||||||
assert "2002-11-20 " in registered
|
assert "2002-11-20 " in registered
|
||||||
|
|
||||||
def test_get_user_unixtime_registration(self) -> None:
|
def test_get_user_unixtime_registration(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -87,7 +84,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Just check date because of timezones
|
# Just check date because of timezones
|
||||||
assert unixtime_registered == 1037793040
|
assert unixtime_registered == 1037793040
|
||||||
|
|
||||||
def test_get_countryless_user(self) -> None:
|
def test_get_countryless_user(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Currently test_user has no country set:
|
# Currently test_user has no country set:
|
||||||
lastfm_user = self.network.get_user("test_user")
|
lastfm_user = self.network.get_user("test_user")
|
||||||
|
@ -98,7 +95,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert country is None
|
assert country is None
|
||||||
|
|
||||||
def test_user_get_country(self) -> None:
|
def test_user_get_country(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user("RJ")
|
lastfm_user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -108,7 +105,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert str(country) == "United Kingdom"
|
assert str(country) == "United Kingdom"
|
||||||
|
|
||||||
def test_user_equals_none(self) -> None:
|
def test_user_equals_none(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
|
|
||||||
|
@ -118,7 +115,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert not value
|
assert not value
|
||||||
|
|
||||||
def test_user_not_equal_to_none(self) -> None:
|
def test_user_not_equal_to_none(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
|
|
||||||
|
@ -128,7 +125,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert value
|
assert value
|
||||||
|
|
||||||
def test_now_playing_user_with_no_scrobbles(self) -> None:
|
def test_now_playing_user_with_no_scrobbles(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Currently test-account has no scrobbles:
|
# Currently test-account has no scrobbles:
|
||||||
user = self.network.get_user("test-account")
|
user = self.network.get_user("test-account")
|
||||||
|
@ -139,7 +136,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert current_track is None
|
assert current_track is None
|
||||||
|
|
||||||
def test_love_limits(self) -> None:
|
def test_love_limits(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
# Currently test-account has at least 23 loved tracks:
|
# Currently test-account has at least 23 loved tracks:
|
||||||
user = self.network.get_user("test-user")
|
user = self.network.get_user("test-user")
|
||||||
|
@ -150,7 +147,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert len(user.get_loved_tracks(limit=None)) >= 23
|
assert len(user.get_loved_tracks(limit=None)) >= 23
|
||||||
assert len(user.get_loved_tracks(limit=0)) >= 23
|
assert len(user.get_loved_tracks(limit=0)) >= 23
|
||||||
|
|
||||||
def test_user_is_hashable(self) -> None:
|
def test_user_is_hashable(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user(self.username)
|
user = self.network.get_user(self.username)
|
||||||
|
|
||||||
|
@ -171,7 +168,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# # Assert
|
# # Assert
|
||||||
# self.assertGreaterEqual(len(tracks), 0)
|
# self.assertGreaterEqual(len(tracks), 0)
|
||||||
|
|
||||||
def test_pickle(self) -> None:
|
def test_pickle(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
@ -189,21 +186,16 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert lastfm_user == loaded_user
|
assert lastfm_user == loaded_user
|
||||||
|
|
||||||
@pytest.mark.xfail
|
@pytest.mark.xfail
|
||||||
def test_cacheable_user(self) -> None:
|
def test_cacheable_user(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_authenticated_user()
|
lastfm_user = self.network.get_authenticated_user()
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_validate_cacheable(lastfm_user, "get_friends")
|
self.helper_validate_cacheable(lastfm_user, "get_friends")
|
||||||
# no cover whilst xfail:
|
self.helper_validate_cacheable(lastfm_user, "get_loved_tracks")
|
||||||
self.helper_validate_cacheable( # pragma: no cover
|
self.helper_validate_cacheable(lastfm_user, "get_recent_tracks")
|
||||||
lastfm_user, "get_loved_tracks"
|
|
||||||
)
|
|
||||||
self.helper_validate_cacheable( # pragma: no cover
|
|
||||||
lastfm_user, "get_recent_tracks"
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_user_get_top_tags_with_limit(self) -> None:
|
def test_user_get_top_tags_with_limit(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -213,7 +205,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
|
self.helper_only_one_thing_in_top_list(tags, pylast.Tag)
|
||||||
|
|
||||||
def test_user_top_tracks(self) -> None:
|
def test_user_top_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user("RJ")
|
lastfm_user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -223,14 +215,14 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
self.helper_two_different_things_in_top_list(things, pylast.Track)
|
||||||
|
|
||||||
def helper_assert_chart(self, chart, expected_type) -> None:
|
def helper_assert_chart(self, chart, expected_type):
|
||||||
# Assert
|
# Assert
|
||||||
assert chart is not None
|
assert chart is not None
|
||||||
assert len(chart) > 0
|
assert len(chart) > 0
|
||||||
assert isinstance(chart[0], pylast.TopItem)
|
assert isinstance(chart[0], pylast.TopItem)
|
||||||
assert isinstance(chart[0].item, expected_type)
|
assert isinstance(chart[0].item, expected_type)
|
||||||
|
|
||||||
def helper_get_assert_charts(self, thing, date) -> None:
|
def helper_get_assert_charts(self, thing, date):
|
||||||
# Arrange
|
# Arrange
|
||||||
album_chart, track_chart = None, None
|
album_chart, track_chart = None, None
|
||||||
(from_date, to_date) = date
|
(from_date, to_date) = date
|
||||||
|
@ -247,14 +239,14 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
self.helper_assert_chart(album_chart, pylast.Album)
|
self.helper_assert_chart(album_chart, pylast.Album)
|
||||||
self.helper_assert_chart(track_chart, pylast.Track)
|
self.helper_assert_chart(track_chart, pylast.Track)
|
||||||
|
|
||||||
def helper_dates_valid(self, dates) -> None:
|
def helper_dates_valid(self, dates):
|
||||||
# Assert
|
# Assert
|
||||||
assert len(dates) >= 1
|
assert len(dates) >= 1
|
||||||
assert isinstance(dates[0], tuple)
|
assert isinstance(dates[0], tuple)
|
||||||
(start, end) = dates[0]
|
(start, end) = dates[0]
|
||||||
assert start < end
|
assert start < end
|
||||||
|
|
||||||
def test_user_charts(self) -> None:
|
def test_user_charts(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user("RJ")
|
lastfm_user = self.network.get_user("RJ")
|
||||||
dates = lastfm_user.get_weekly_chart_dates()
|
dates = lastfm_user.get_weekly_chart_dates()
|
||||||
|
@ -263,7 +255,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
self.helper_get_assert_charts(lastfm_user, dates[0])
|
self.helper_get_assert_charts(lastfm_user, dates[0])
|
||||||
|
|
||||||
def test_user_top_artists(self) -> None:
|
def test_user_top_artists(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
|
|
||||||
|
@ -273,7 +265,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
self.helper_only_one_thing_in_top_list(artists, pylast.Artist)
|
||||||
|
|
||||||
def test_user_top_albums(self) -> None:
|
def test_user_top_albums(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -287,7 +279,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert len(top_album.info["image"])
|
assert len(top_album.info["image"])
|
||||||
assert re.search(r"^http.+$", top_album.info["image"][pylast.SIZE_LARGE])
|
assert re.search(r"^http.+$", top_album.info["image"][pylast.SIZE_LARGE])
|
||||||
|
|
||||||
def test_user_tagged_artists(self) -> None:
|
def test_user_tagged_artists(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
tags = ["artisttagola"]
|
tags = ["artisttagola"]
|
||||||
|
@ -300,7 +292,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_list(artists, pylast.Artist)
|
self.helper_only_one_thing_in_list(artists, pylast.Artist)
|
||||||
|
|
||||||
def test_user_tagged_albums(self) -> None:
|
def test_user_tagged_albums(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
tags = ["albumtagola"]
|
tags = ["albumtagola"]
|
||||||
|
@ -313,7 +305,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_list(albums, pylast.Album)
|
self.helper_only_one_thing_in_list(albums, pylast.Album)
|
||||||
|
|
||||||
def test_user_tagged_tracks(self) -> None:
|
def test_user_tagged_tracks(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user(self.username)
|
lastfm_user = self.network.get_user(self.username)
|
||||||
tags = ["tracktagola"]
|
tags = ["tracktagola"]
|
||||||
|
@ -326,7 +318,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_only_one_thing_in_list(tracks, pylast.Track)
|
self.helper_only_one_thing_in_list(tracks, pylast.Track)
|
||||||
|
|
||||||
def test_user_subscriber(self) -> None:
|
def test_user_subscriber(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
subscriber = self.network.get_user("RJ")
|
subscriber = self.network.get_user("RJ")
|
||||||
non_subscriber = self.network.get_user("Test User")
|
non_subscriber = self.network.get_user("Test User")
|
||||||
|
@ -339,7 +331,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert subscriber_is_subscriber
|
assert subscriber_is_subscriber
|
||||||
assert not non_subscriber_is_subscriber
|
assert not non_subscriber_is_subscriber
|
||||||
|
|
||||||
def test_user_get_image(self) -> None:
|
def test_user_get_image(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -347,9 +339,9 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
url = user.get_image()
|
url = user.get_image()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert url.startswith("https://")
|
self.assert_startswith(url, "https://")
|
||||||
|
|
||||||
def test_user_get_library(self) -> None:
|
def test_user_get_library(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user(self.username)
|
user = self.network.get_user(self.username)
|
||||||
|
|
||||||
|
@ -359,7 +351,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert isinstance(library, pylast.Library)
|
assert isinstance(library, pylast.Library)
|
||||||
|
|
||||||
def test_get_recent_tracks_from_to(self) -> None:
|
def test_get_recent_tracks_from_to(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user("RJ")
|
lastfm_user = self.network.get_user("RJ")
|
||||||
start = dt.datetime(2011, 7, 21, 15, 10)
|
start = dt.datetime(2011, 7, 21, 15, 10)
|
||||||
|
@ -376,7 +368,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert str(tracks[0].track.artist) == "Johnny Cash"
|
assert str(tracks[0].track.artist) == "Johnny Cash"
|
||||||
assert str(tracks[0].track.title) == "Ring of Fire"
|
assert str(tracks[0].track.title) == "Ring of Fire"
|
||||||
|
|
||||||
def test_get_recent_tracks_limit_none(self) -> None:
|
def test_get_recent_tracks_limit_none(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
lastfm_user = self.network.get_user("bbc6music")
|
lastfm_user = self.network.get_user("bbc6music")
|
||||||
start = dt.datetime(2020, 2, 15, 15, 00)
|
start = dt.datetime(2020, 2, 15, 15, 00)
|
||||||
|
@ -395,24 +387,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert str(tracks[0].track.artist) == "Seun Kuti & Egypt 80"
|
assert str(tracks[0].track.artist) == "Seun Kuti & Egypt 80"
|
||||||
assert str(tracks[0].track.title) == "Struggles Sounds"
|
assert str(tracks[0].track.title) == "Struggles Sounds"
|
||||||
|
|
||||||
def test_get_recent_tracks_is_streamable(self) -> None:
|
def test_get_playcount(self):
|
||||||
# Arrange
|
|
||||||
lastfm_user = self.network.get_user("bbc6music")
|
|
||||||
start = dt.datetime(2020, 2, 15, 15, 00)
|
|
||||||
end = dt.datetime(2020, 2, 15, 15, 40)
|
|
||||||
|
|
||||||
utc_start = calendar.timegm(start.utctimetuple())
|
|
||||||
utc_end = calendar.timegm(end.utctimetuple())
|
|
||||||
|
|
||||||
# Act
|
|
||||||
tracks = lastfm_user.get_recent_tracks(
|
|
||||||
time_from=utc_start, time_to=utc_end, limit=None, stream=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Assert
|
|
||||||
assert inspect.isgenerator(tracks)
|
|
||||||
|
|
||||||
def test_get_playcount(self) -> None:
|
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -422,7 +397,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert playcount >= 128387
|
assert playcount >= 128387
|
||||||
|
|
||||||
def test_get_image(self) -> None:
|
def test_get_image(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -430,10 +405,10 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
image = user.get_image()
|
image = user.get_image()
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert image.startswith("https://")
|
self.assert_startswith(image, "https://")
|
||||||
assert image.endswith(".png")
|
self.assert_endswith(image, ".png")
|
||||||
|
|
||||||
def test_get_url(self) -> None:
|
def test_get_url(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("RJ")
|
user = self.network.get_user("RJ")
|
||||||
|
|
||||||
|
@ -443,7 +418,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
# Assert
|
# Assert
|
||||||
assert url == "https://www.last.fm/user/rj"
|
assert url == "https://www.last.fm/user/rj"
|
||||||
|
|
||||||
def test_get_weekly_artist_charts(self) -> None:
|
def test_get_weekly_artist_charts(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("bbc6music")
|
user = self.network.get_user("bbc6music")
|
||||||
|
|
||||||
|
@ -455,7 +430,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert artist is not None
|
assert artist is not None
|
||||||
assert isinstance(artist.network, pylast.LastFMNetwork)
|
assert isinstance(artist.network, pylast.LastFMNetwork)
|
||||||
|
|
||||||
def test_get_weekly_track_charts(self) -> None:
|
def test_get_weekly_track_charts(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
user = self.network.get_user("bbc6music")
|
user = self.network.get_user("bbc6music")
|
||||||
|
|
||||||
|
@ -467,7 +442,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert track is not None
|
assert track is not None
|
||||||
assert isinstance(track.network, pylast.LastFMNetwork)
|
assert isinstance(track.network, pylast.LastFMNetwork)
|
||||||
|
|
||||||
def test_user_get_track_scrobbles(self) -> None:
|
def test_user_get_track_scrobbles(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "France Gall"
|
artist = "France Gall"
|
||||||
title = "Laisse Tomber Les Filles"
|
title = "Laisse Tomber Les Filles"
|
||||||
|
@ -481,7 +456,7 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
assert str(scrobbles[0].track.artist) == "France Gall"
|
assert str(scrobbles[0].track.artist) == "France Gall"
|
||||||
assert scrobbles[0].track.title == "Laisse Tomber Les Filles"
|
assert scrobbles[0].track.title == "Laisse Tomber Les Filles"
|
||||||
|
|
||||||
def test_cacheable_user_get_track_scrobbles(self) -> None:
|
def test_cacheable_user_get_track_scrobbles(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
artist = "France Gall"
|
artist = "France Gall"
|
||||||
title = "Laisse Tomber Les Filles"
|
title = "Laisse Tomber Les Filles"
|
||||||
|
@ -489,8 +464,20 @@ class TestPyLastUser(TestPyLastWithLastFm):
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
result1 = user.get_track_scrobbles(artist, title, cacheable=False)
|
result1 = user.get_track_scrobbles(artist, title, cacheable=False)
|
||||||
result2 = list(user.get_track_scrobbles(artist, title, cacheable=True))
|
result2 = user.get_track_scrobbles(artist, title, cacheable=True)
|
||||||
result3 = list(user.get_track_scrobbles(artist, title))
|
result3 = user.get_track_scrobbles(artist, title)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.helper_validate_results(result1, result2, result3)
|
self.helper_validate_results(result1, result2, result3)
|
||||||
|
|
||||||
|
def test_get_artist_tracks_deprecated(self):
|
||||||
|
# Arrange
|
||||||
|
lastfm_user = self.network.get_user(self.username)
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
with warnings.catch_warnings(), pytest.raises(
|
||||||
|
pylast.WSError,
|
||||||
|
match="Deprecated - This type of request is no longer supported",
|
||||||
|
):
|
||||||
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||||
|
lastfm_user.get_artist_tracks(artist="Test Artist")
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def mock_network():
|
def mock_network():
|
||||||
|
@ -20,51 +17,12 @@ def mock_network():
|
||||||
"fdasfdsafsaf not unicode",
|
"fdasfdsafsaf not unicode",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_get_cache_key(artist) -> None:
|
def test_get_cache_key(artist):
|
||||||
request = pylast._Request(mock_network(), "some_method", params={"artist": artist})
|
request = pylast._Request(mock_network(), "some_method", params={"artist": artist})
|
||||||
request._get_cache_key()
|
request._get_cache_key()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("obj", [pylast.Artist("B\xe9l", mock_network())])
|
@pytest.mark.parametrize("obj", [pylast.Artist("B\xe9l", mock_network())])
|
||||||
def test_cast_and_hash(obj) -> None:
|
def test_cast_and_hash(obj):
|
||||||
assert isinstance(str(obj), str)
|
assert type(str(obj)) is str
|
||||||
assert isinstance(hash(obj), int)
|
assert isinstance(hash(obj), int)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"test_input, expected",
|
|
||||||
[
|
|
||||||
(
|
|
||||||
# Plain text
|
|
||||||
'<album mbid="">test album name</album>',
|
|
||||||
'<album mbid="">test album name</album>',
|
|
||||||
),
|
|
||||||
(
|
|
||||||
# Contains Unicode ENQ Enquiry control character
|
|
||||||
'<album mbid="">test album \u0005name</album>',
|
|
||||||
'<album mbid="">test album name</album>',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test__remove_invalid_xml_chars(test_input: str, expected: str) -> None:
|
|
||||||
assert pylast._remove_invalid_xml_chars(test_input) == expected
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"test_input, expected",
|
|
||||||
[
|
|
||||||
(
|
|
||||||
# Plain text
|
|
||||||
'<album mbid="">test album name</album>',
|
|
||||||
'<?xml version="1.0" ?><album mbid="">test album name</album>',
|
|
||||||
),
|
|
||||||
(
|
|
||||||
# Contains Unicode ENQ Enquiry control character
|
|
||||||
'<album mbid="">test album \u0005name</album>',
|
|
||||||
'<?xml version="1.0" ?><album mbid="">test album name</album>',
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test__parse_response(test_input: str, expected: str) -> None:
|
|
||||||
doc = pylast._parse_response(test_input)
|
|
||||||
assert doc.toxml() == expected
|
|
||||||
|
|
51
tox.ini
51
tox.ini
|
@ -1,40 +1,21 @@
|
||||||
[tox]
|
[tox]
|
||||||
requires =
|
envlist = py{36, 37, 38, 39, 310, py3}
|
||||||
tox>=4.2
|
|
||||||
env_list =
|
|
||||||
lint
|
|
||||||
py{py3, 313, 312, 311, 310, 39, 38}
|
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
extras =
|
extras = tests
|
||||||
tests
|
setenv =
|
||||||
pass_env =
|
PYLAST_USERNAME={env:PYLAST_USERNAME:}
|
||||||
FORCE_COLOR
|
PYLAST_PASSWORD_HASH={env:PYLAST_PASSWORD_HASH:}
|
||||||
PYLAST_API_KEY
|
PYLAST_API_KEY={env:PYLAST_API_KEY:}
|
||||||
PYLAST_API_SECRET
|
PYLAST_API_SECRET={env:PYLAST_API_SECRET:}
|
||||||
PYLAST_PASSWORD_HASH
|
commands = pytest -v -s -W all --cov pylast --cov-report term-missing --random-order {posargs}
|
||||||
PYLAST_USERNAME
|
|
||||||
commands =
|
|
||||||
{envpython} -m pytest -v -s -W all \
|
|
||||||
--cov pylast \
|
|
||||||
--cov tests \
|
|
||||||
--cov-report html \
|
|
||||||
--cov-report term-missing \
|
|
||||||
--cov-report xml \
|
|
||||||
--random-order \
|
|
||||||
{posargs}
|
|
||||||
|
|
||||||
[testenv:lint]
|
|
||||||
skip_install = true
|
|
||||||
deps =
|
|
||||||
pre-commit
|
|
||||||
pass_env =
|
|
||||||
PRE_COMMIT_COLOR
|
|
||||||
commands =
|
|
||||||
pre-commit run --all-files --show-diff-on-failure
|
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
deps =
|
deps = ipdb
|
||||||
ipdb
|
commands = {posargs}
|
||||||
commands =
|
|
||||||
{posargs}
|
[testenv:lint]
|
||||||
|
deps = pre-commit
|
||||||
|
commands = pre-commit run --all-files --show-diff-on-failure
|
||||||
|
skip_install = true
|
||||||
|
passenv = PRE_COMMIT_COLOR
|
||||||
|
|
Loading…
Reference in a new issue