nixosTests.mpd: port to python

This commit is contained in:
Florian Klink 2019-11-22 21:21:05 +01:00
parent c81e4f10c2
commit 5121706951

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }:
import ./make-test-python.nix ({ pkgs, lib, ... }:
let
track = pkgs.fetchurl {
# Sourced from http://freemusicarchive.org/music/Blue_Wave_Theory/Surf_Music_Month_Challenge/Skyhawk_Beach_fade_in
@ -94,40 +94,39 @@ import ./make-test.nix ({ pkgs, lib, ... }:
};
testScript = ''
my $mpc = "${pkgs.mpc_cli}/bin/mpc --wait";
mpc = "${pkgs.mpc_cli}/bin/mpc --wait"
# Connects to the given server and attempts to play a tune.
sub play_some_music {
my $server = $_[0];
def play_some_music(server):
server.wait_for_unit("mpd.service")
server.succeed(f"{mpc} update")
_, tracks = server.execute(f"{mpc} ls")
$server->waitForUnit("mpd.service");
$server->succeed("$mpc update");
my @tracks = $server->execute("$mpc ls");
for track in tracks.splitlines():
server.succeed(f"{mpc} add {track}")
for my $track (split(/\n/, $tracks[1])) {
$server->succeed("$mpc add $track");
};
_, added_tracks = server.execute(f"{mpc} listall")
my @added_tracks = $server->execute("$mpc listall");
(length $added_tracks[1]) > 0 or die "Failed to add audio tracks to the playlist.";
# Check we succeeded adding audio tracks to the playlist
assert len(added_tracks.splitlines()) > 0
$server->succeed("$mpc play");
server.succeed(f"{mpc} play")
my @status = $server->execute("$mpc status");
my @output = split(/\n/, $status[1]);
$output[1] =~ /.*playing.*/ or die "Audio track is not playing, as expected.";
_, output = server.execute(f"{mpc} status")
# Assure audio track is playing
assert "playing" in output
$server->succeed("$mpc stop");
};
server.succeed(f"{mpc} stop")
play_some_music($serverALSA);
play_some_music($serverPulseAudio);
$client->waitForUnit("multi-user.target");
$client->succeed("$mpc -h serverALSA status");
play_some_music(serverALSA)
play_some_music(serverPulseAudio)
client.wait_for_unit("multi-user.target")
client.succeed(f"{mpc} -h serverALSA status")
# The PulseAudio-based server is configured not to accept external client connections
# to perform the following test:
$client->fail("$mpc -h serverPulseAudio status");
client.fail(f"{mpc} -h serverPulseAudio status")
'';
})