Skip to content

Commit

Permalink
Merge pull request #38 from open-dynaMIX/tests
Browse files Browse the repository at this point in the history
chore: add backend test infrastructure
  • Loading branch information
open-dynaMIX authored Apr 17, 2020
2 parents c83b994 + a318167 commit eb92016
Show file tree
Hide file tree
Showing 30 changed files with 886 additions and 199 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Screenshots/
.dockerignore
.git/
.github/
.gitignore
.idea/
.pytest_cache/
README.md
LICENSE
CHANGELOG.md
CONTRIBUTING.md
19 changes: 0 additions & 19 deletions .github/workflows/commitlint.yml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0'

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the webui container
run: docker-compose -f docker-compose.yml build --pull
working-directory: ./tests
- name: Run test suite
run: docker-compose -f docker-compose.yml run --rm webui pytest ./tests.py -vv
working-directory: ./tests
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: '3.8'
- name: Install requirements
run: pip install -r requirements.txt
working-directory: ./tests
- name: Run black and flake8
run: |
black --check --diff ./
flake8
working-directory: ./tests
commit-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: '3.8'
- name: Install gitlint
run: pip install gitlint
- name: Run gitlint
run: gitlint --contrib contrib-title-conventional-commits --ignore B5,B6
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.htpasswd
dummy/
__pycache__/
57 changes: 57 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Contributing

Contributions are very welcome!

## Tooling
Docker, docker-compose and some python tooling is used in development and testing, because that's what I know best :)

## The ./tests directory

All commands you'll need during dev are only available from within the `./tests` directory.

```shell
cd ./tests
```

## Building the testing container

```shell
make build
```

## Running the tests

```shell
make tests
```

## Formatting & Linting the python tests

For formatting and linting the python tests, following tools are used:

- black
- isort
- flake8

## conventional commits
For automatically generating release notes, commit messages are parsed. This only works, if they follow the
[Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/).


## Setup pre commit
Pre commit hooks is an additional option instead of linting and formatting checks in your editor of choice.

First create a virtualenv with the tool of your choice before running below commands:

pip install pre-commit
pip install -r requirements.txt
pre-commit install --hook=pre-commit
pre-commit install --hook=commit-msg

## Generating the release notes
Make sure [python-semantic-release](https://github.com/relekang/python-semantic-release) is
installed and then run

```shell
make release-notes
```
115 changes: 61 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# simple-mpv-webui
...is a web based user interface with controls for the [mpv mediaplayer](https://mpv.io/).

[![Build Status](https://github.com/open-dynaMIX/raiseorlaunch/workflows/Tests/badge.svg)](https://github.com/open-dynaMIX/simple-mpv-webui/actions?query=workflow%3ATests)
[![License](https://img.shields.io/badge/license-MIT-green)](https://opensource.org/licenses/MIT)

A web based user interface with controls for the [mpv mediaplayer](https://mpv.io/).

## Usage
To use it, simply copy `webui.lua` and the `webui-page`-folder to `~/.config/mpv/scripts/`, mpv will then run it
Expand Down Expand Up @@ -150,15 +154,15 @@ You can also directly talk to the endpoints:
| /api/playlist_move_up/:index | POST | `int` | Move playlist item at position `:index` one position up |
| /api/playlist_remove/:index | POST | `int` | Remove playlist item at position `:index` |
| /api/playlist_shuffle | POST | | Shuffle the playlist |
| /api/loop_file/:mode | POST | `string` or `int` | Loop the current file. `:mode` accepts the same loop modes as mpv |
| /api/loop_playlisr/:mode | POST | `string` or `int` | Loop the whole playlist `:mode` accepts the same loop modes as mpv |
| /api/loop_file/:mode | POST | `string` or `int` | Loop the current file. `:mode` accepts the same loop modes as mpv |
| /api/loop_playlist/:mode | POST | `string` or `int` | Loop the whole playlist `:mode` accepts the same loop modes as mpv |
| /api/add_chapter/:amount | POST | `int` (can be negative) | Jump `:amount` chapters in current media |
| /api/add_volume/:percent | POST | `int` or `float` (can be negative) | Add :percent% volume |
| /api/set_volume/:percent | POST | `int` or `float` | Set volume to :percent% |
| /api/add_sub_delay/:ms | POST | `int` or `float` (can be negative) | Add :ms milliseconds subtitles delay |
| /api/add_sub_delay/:ms | POST | `int` or `float` (can be negative) | Add :seconds seconds subtitles delay |
| /api/set_sub_delay/:ms | POST | `int` or `float` (can be negative) | Set subtitles delay to :ms milliseconds |
| /api/add_audio_delay/:ms | POST | `int` or `float` (can be negative) | Add :ms miliseconds audio delay |
| /api/set_audio_delay/:ms | POST | `int` or `float` (can be negative) | Set audio delay to :ms milliseconds |
| /api/add_audio_delay/:seconds | POST | `int` or `float` (can be negative) | Add :seconds seconds audio delay |
| /api/set_audio_delay/:seconds | POST | `int` or `float` (can be negative) | Set audio delay to :seconds milliseconds |
| /api/cycle_sub | POST | | Cycle trough available subtitles |
| /api/cycle_audio | POST | | Cycle trough available audio tracks |
| /api/cycle_audio_device | POST | | Cycle trough audio devices. [More information.](#audio-devices-string) |
Expand All @@ -171,63 +175,65 @@ information about the error.

``` json
{
"filename": "big_buck_bunny_1080p_stereo.ogg",
"audio-delay": 0, # <-- milliseconds
"audio-devices": [
{"active": True, "description": "Autoselect device", "name": "auto"},
{"active": False, "description": "Default (alsa)", "name": "alsa"},
{"active": False, "description": "Default (jack)", "name": "jack"},
{"active": False, "description": "Default (sdl)", "name": "sdl"},
{"active": False, "description": "Default (sndio)", "name": "sndio"},
],
"chapter": 0, # <-- current chapter
"chapters": 0, # <-- chapters count
"duration": 596, # <-- seconds
"position": 122, # <-- seconds
"pause": true,
"remaining": 474, # <-- seconds
"sub-delay": 0, # <-- milliseconds
"audio-delay": 0, # <-- milliseconds
"fullscreen": false,
"loop-file": "no", # <-- `no`, `inf` or integer
"loop-playlist": "no", # <-- `no`, `inf`, `force` or integer
"metadata": {}, # <-- all metadata available to MPV
"track-list": [ # <-- all available video, audio and sub tracks
"duration": 6.024, # <-- seconds
"filename": "01 - dummy.mp3",
"fullscreen": False,
"loop-file": false, # <-- false, `inf` or integer
"loop-playlist": false, # <-- false, `inf`, `force` or integer
"metadata": { # <-- all metadata available to MPV
"album": "Dummy Album",
"artist": "Dummy Artist",
"comment": "0",
"date": "2020",
"encoder": "Lavc57.10",
"genre": "Jazz",
"title": "First dummy",
},
"pause": True,
"playlist": [
{
"id": 1,
"type": "video",
"src-id": 0,
"albumart": false,
"default": false,
"forced": false,
"external": false,
"selected": true,
"ff-index": 0,
"decoder-desc": "theora (Theora)",
"codec": "theora",
"demux-w": 1920,
"demux-h": 1080
"current": True,
"filename": "./environment/test_media/01 - dummy.mp3",
"playing": True,
},
{"filename": "./environment/test_media/02 - dummy.mp3"},
{"filename": "./environment/test_media/03 - dummy.mp3"},
],
"position": -0.0, # <-- seconds
"remaining": 6.024, # <-- seconds
"sub-delay": 0, # <-- milliseconds
"track-list": [ # <-- all available video, audio and sub tracks
{
"id": 1,
"type": "audio",
"src-id": 0,
"albumart": False,
"audio-channels": 2,
"albumart": false,
"default": false,
"forced": false,
"external": false,
"selected": true,
"ff-index": 1,
"decoder-desc": "vorbis (Vorbis)",
"codec": "vorbis",
"codec": "mp3",
"decoder-desc": "mp3float (MP3 (MPEG audio layer 3))",
"default": False,
"demux-channel-count": 2,
"demux-channels": "stereo",
"demux-samplerate": 48000
"demux-samplerate": 48000,
"dependent": False,
"external": False,
"ff-index": 0,
"forced": False,
"id": 1,
"selected": True,
"src-id": 0,
"type": "audio",
}
],
"volume": 64,
"volume": 0,
"volume-max": 130,
"audio-support": true, # <-- is set to `false` if only the `auto` audio device is found by mpv
"playlist": [ # <-- all files in the current playlist
{
"filename": "Videos/big_buck_bunny_1080p_stereo.ogg",
"current": true,
"playing": true
}
]
}
```

Expand All @@ -242,5 +248,6 @@ Thanks to [makedin](https://github.com/makedin) for his work on this.
- Option to set the port being used (defaults to 8080)
- Using the Media Session API

## Warning
These are my first steps with lua, so I'm just happy it works.
## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).
37 changes: 0 additions & 37 deletions dev_helpers/CONTRIBUTING.md

This file was deleted.

18 changes: 0 additions & 18 deletions dev_helpers/commit-msg

This file was deleted.

4 changes: 0 additions & 4 deletions dev_helpers/generate_release_notes.sh

This file was deleted.

2 changes: 0 additions & 2 deletions dev_helpers/requirements.txt

This file was deleted.

27 changes: 27 additions & 0 deletions tests/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: local
hooks:
- id: black
stages: [commit]
name: black
language: system
entry: black
types: [python]
- id: isort
stages: [commit]
name: isort
language: system
entry: isort -y
types: [python]
- id: flake8
stages: [commit]
name: flake8
language: system
entry: flake8
types: [python]
- id: gitlint
stages: [commit-msg]
name: gitlint
description: Validate commit lint
entry: gitlint --ignore B5,B6 --msg-filename
language: system
Loading

0 comments on commit eb92016

Please sign in to comment.