Commit graph

87 commits

Author SHA1 Message Date
Andrew Rogl
1ec87a3bdd pyupgrade beetsplug and tests
All tests working
More tidy up to be done
2021-08-26 19:12:51 +10:00
Adrian Sampson
5db2b4ccaa Fix new flake8 warnings 2020-05-13 08:20:50 -04:00
Zsin Skri
088af4d171 bpd tests: skip control_port in queue
When setting up bpd tests, two servers are startet: first a control server, then
bpd. Both send their assigned ports down a queue. The recipient only needs bpd's
port and thus skips the first queue entry.
2019-07-17 19:05:51 +02:00
Zsin Skri
8ba79117d9 bpd tests: use mp.Queue to communicate assigned port
Use a `multiprocessing.Queue` instead of a `multiprocessing.Value` to avoid the
manual polling/timeout handling.

TODO: Strangely Listener seems to be constructed twice. Only the second one is
used. Fix that and then remove the code working around it.
2019-07-17 16:19:17 +02:00
Zsin Skri
871f79c8f2 bpd tests: close only existing sockets
Close sockets in `finally`-clauses only after they have actually been created.
2019-07-17 13:38:57 +02:00
Zsin Skri
fb07a5112a bpd tests: terminate server upon connection failure 2019-07-17 13:21:25 +02:00
Zsin Skri
bbda292145 bpd test: make start_server a freestanding function
Under some circumstances (maybe under MS Windows?) local objects can't be
pickled. When `start_server` is a local this causes a crash:
https://ci.appveyor.com/project/beetbox/beets/builds/25996163/job/rbp3frnkwsvbuwx6#L541

Make `start_server` a freestanding function to mitigate this.
2019-07-15 22:25:48 +02:00
Zsin Skri
0ebab5edaa fix "Sporadic test failures in BPD tests #3309"
The bpd test bind a socket in order to test the protocol implementation. When
running concurrently this often resulted in an attempt to bind an already
occupied port.

By using the port number `0` we instead let the OS choose a free port. We then
have to extract it from the socket (which is handled by `bluelet`) via
`mock.patch`ing.
2019-07-15 21:25:39 +02:00
Carl Suster
62aa358ce7 bpd: bump protocol version to 0.16 2019-06-02 23:37:07 +10:00
Carl Suster
d8be83bc0d bpd: support ranges in playlistid 2019-06-02 23:37:07 +10:00
Carl Suster
dc7e3b9b6a bpd: support nextsong in status 2019-06-02 23:37:07 +10:00
Carl Suster
fdd809fd36 bpd: support more tagtypes 2019-06-02 23:37:07 +10:00
Carl Suster
27c462d287 bpd: make noidle a no-op outside idle mode
The real MPD ignores `noidle` when the client is not idle. It doesn't
even send a successful response, just ignores the command. Although
I don't understand why a client would fail to keep track of its own
state, it seems that this is necessary to get ncmpcpp working.
2019-06-02 23:37:07 +10:00
Carl Suster
1a5263b68f bpd: support volume command for real 2019-06-02 23:37:07 +10:00
Carl Suster
5c37a58ad6 bpd: add more tests 2019-06-02 23:37:07 +10:00
Carl Suster
59c506990a bpd: fix bug in playlistid
The playlistid command is supposed to list the whole playlist if no
argument is provided, but we were accidentally trying to look up an
impossible negative id in that case causing an error to always be
returned.
2019-06-02 23:37:07 +10:00
Carl Suster
d2f13bf65c confit: replace with confuse in tests 2019-06-01 10:13:13 +10:00
Adrian Sampson
99778d9ece bpd tests: Randomize port number
This is a hacky but effective way to work around a problem when running
the tests in parallel where two different test executions want to use
the same port.
2019-05-30 12:02:47 -04:00
Carl Suster
3da23167ca bpd: support decoders command
This uses GStreamer APIs to extract a list of audio decoders and the
relevant MIME types and file extensions. Some clients like ncmpcpp use
this command to fetch a list of supported file extensions.
2019-04-19 16:08:05 +10:00
Carl Suster
9182f18e6f bpd: support short form of list command for albums
Some clients list the albums belonging to an artist by issuing the
command `list album <ARTIST NAME>`. This change inserts the tag `artist`
before the artist name so that this succeeds. Fixes #3007
2019-04-15 13:25:02 +10:00
Carl Suster
d55f061f0b bpd: add control socket
A new `ControlConnection` is created each time a client connects over
a new control socket. This is used to forward events from the player,
and also for debugging utilities that are not part of the real MPD
protocol.

This new feature reuses as much infrastructure from the normal protocol
handling as possible (e.g. `Command` for parsing messages). While the
normal connection delegates to server `cmd_*` methods which are string
generators, the control connections delegate to `ctrl_*` methods defined
on the connection itself that are full coroutines.
2019-04-09 12:19:15 +10:00
Carl Suster
6fbf3853f2 bpd: bump protocol version to 0.14.0 2019-04-08 11:40:24 +10:00
Carl Suster
d05ca2c2b0 bpd: add tests for idle command 2019-04-08 11:40:24 +10:00
Carl Suster
ee0c31ba6a bpd: track and log client session details
Keep track of a list of currently-connected clients.

Use `socket.getpeername()` to get an identifier for each connection and
include this in each log message. This function is documented as not
being available on all systems, but it's unclear which systems this
involves.

Also log a message on client connect and disconnect events. If the
disconnection reason is because the client sent a blank line, match MPD
by returning a protocol error then hanging up. Escape curly braces.
2019-04-08 11:28:56 +10:00
Carl Suster
5b0a02eb31 bpd: don't send volume if zero in status 2019-04-08 10:52:15 +10:00
Carl Suster
e839e4ea19 bpd: improve exception handling
Check function signature instead of using TypeError to crudely guess
that the wrong number of arguments were provided.

Prevent bpd from crashing when trying to log a traceback. The
`traceback.format_exc` function takes an optional argument which is
supposed to be an integer restricting the length of the backtrace to
show. Instead we were passing the exception object to this function and
causing a new exception to be raised.
2019-04-02 09:39:07 +11:00
Carl Suster
146c5f5e13 bpd: fix repeat, consume and single in reverse
These flags are all relevant to the 'previous' command as well as the
'next' command.
2019-04-01 18:05:10 +11:00
Carl Suster
12e49b3c88 bpd: skipping backwards through zero keeps playing
Previously issuing the 'previous' command when at position 0 on the
playlist would cause bpd to stop playing. MPD instead just restarts the
currently playing song instead, so we now match this behaviour.
2019-04-01 17:51:21 +11:00
Carl Suster
a4fe6875a1 bpd: fix bug in bounds check of current song index
The songs are indexed starting from zero for the play command, however
the bound check was off by one. An index matching the length of the
playlist would crash the server instead of responding with an error
message over the protocol.
2019-04-01 17:41:25 +11:00
Carl Suster
0c3a63ef9f bpd: fix repeat mode behaviour
The repeat flag indicates that the entire playlist should be repeated.
If both the repeat and single flags are set then this triggers the old
behaviour of looping over a single track.
2019-04-01 17:39:35 +11:00
Carl Suster
b245c0e755 bpd: test fields returned by status command 2019-04-01 16:42:39 +11:00
Carl Suster
bae9c40600 bpd: support the single command
This command instructs bpd to stop playing when the current song
finishes. In the MPD 0.20 protocol this flag gains a value 'oneshot' but
for now we just support its older version with a boolean value.
2019-04-01 16:30:02 +11:00
Carl Suster
71e7621642 bpd: no-op support for persistent playlists
The real MPD offers persistent playlist manipulation, storing the
playlists in a directory set in the config file. If that directory is
not available then the feature is disabled and the relevant commands all
respond with errors. Based on this, the initial support in bpd just
returns errors matching the MPD server in the disabled mode.

For playlistadd, extend the _bpd_add helper to work with playlists other
than the queue in order to support testing the real implementations of
these commands in the future.
2019-04-01 16:30:02 +11:00
Carl Suster
859e16d1e3 bpd: support consume command 2019-04-01 16:30:02 +11:00
Carl Suster
e5851866d7 bpd: add replay_gain_* commands
There's a special status command for checking the replay gain mode,
which can be set to one of a short list of possible values. For now at
least we can ignore this feature, but track the setting anyway.
2019-04-01 14:49:27 +11:00
Carl Suster
67a0b38d20 bpd: add dummy command for volume
MPD supports a deprecated command 'volume' which was used to change the
volume by a relative amount unlike its replacement 'setvol' which uses
an absolute amount. As far as I can tell 'volume' always responds with a system
error message "No mixer".
2019-04-01 14:49:27 +11:00
Carl Suster
1511e313f7 bpd: add mixramp commands
These are a more sophisticated version of crossfade so we're free to
ignore them, at least for now. We now track the values of the two
settings, and show them in the status output. Like MPD, we suppress the
mixrampdb value if it's set to nan, which is how it signals that the
feature should be turned off.
2019-04-01 14:49:27 +11:00
Carl Suster
0f53ae9a87 bpd: error instead of crashing on extra argument
If an MPC client is expecting a command to take an argument that bpd
isn't expecting (e.g. because of a difference in protocol versions) then
bpd currently crashes completely. Instead, do what the real MPD does and
return an error message over the protocol.
2019-04-01 14:49:27 +11:00
Carl Suster
d94a5393b2 bpd: fix crossfade command
Although crossfade is not implemented in bpd, we can store the setting
and repeat is back to clients. Also log a warning that the operation is
not implemented.

The real MPD doesn't show the crossfade in status if it's zero since
that means no crossfade, so now we don't either.
2019-04-01 14:49:27 +11:00
Carl Suster
de6718abdf bpd: separate tests by command category 2019-04-01 14:49:27 +11:00
Carl Suster
999cf14401 BPD tests: change expectedFailure -> skip for nose 2019-03-31 10:50:42 +11:00
Carl Suster
2e35c27dce BPD tests: improve helpers 2019-03-31 10:46:14 +11:00
Carl Suster
eb5c7513a1 BPD tests: fix GstPlayer mock 2019-03-31 10:46:14 +11:00
Carl Suster
2a2d9b5c98 BPD tests: explicitly close client socket 2019-03-31 10:46:14 +11:00
Carl Suster
a6c976b880 BPD tests: small code reformatting 2019-03-31 10:46:14 +11:00
Carl Suster
3eaf0f7a19 BPD tests: use canonical capitalisation of tags 2019-03-31 10:46:14 +11:00
Carl Suster
4c627cbacb [skip travis] BPD tests: add items by path 2019-03-31 10:46:14 +11:00
Carl Suster
dfc5da70cd BPD tests: avoid os.fsdecode new in Py3.2 2019-03-31 10:46:14 +11:00
Carl Suster
14d0cc3b85 BPD tests: be more careful with paths 2019-03-31 10:46:14 +11:00
Carl Suster
7c8bbd3011 BPD tests: avoid Py3.7-only mp.Process.kill 2019-03-31 10:46:14 +11:00