From 85c9c8e777ed0015532431f8e01ee67e360ccd46 Mon Sep 17 00:00:00 2001 From: Eden Refael Date: Thu, 28 Nov 2024 23:22:32 +0200 Subject: [PATCH] added tests for the amixer sget --- test_file.py | 12 ++++++ .../ubuntu-22.04/amixer-control-capture.json | 1 + .../ubuntu-22.04/amixer-control-capture.out | 6 +++ .../amixer-control-headphone.json | 1 + .../ubuntu-22.04/amixer-control-headphone.out | 7 ++++ .../ubuntu-22.04/amixer-control-master.json | 1 + .../ubuntu-22.04/amixer-control-master.out | 5 +++ .../ubuntu-22.04/amixer-control-speakers.json | 1 + .../ubuntu-22.04/amixer-control-speakers.out | 7 ++++ tests/test_amixer.py | 37 +++++++++++++++++++ 10 files changed, 78 insertions(+) create mode 100644 test_file.py create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-capture.json create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-capture.out create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-headphone.json create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-headphone.out create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-master.json create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-master.out create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-speakers.json create mode 100644 tests/fixtures/ubuntu-22.04/amixer-control-speakers.out create mode 100644 tests/test_amixer.py diff --git a/test_file.py b/test_file.py new file mode 100644 index 00000000..8cf25450 --- /dev/null +++ b/test_file.py @@ -0,0 +1,12 @@ +import jc + +data_sget_headphones = """Simple mixer control 'Headphone',0 + Capabilities: pvolume pswitch + Playback channels: Front Left - Front Right + Limits: Playback 0 - 87 + Mono: + Front Left: Playback 0 [0%] [-65.25dB] [off] + Front Right: Playback 0 [0%] [-65.25dB] [off]""" + +output_data_sget_headphones = jc.parse("amixer", data_sget_headphones) +print(output_data_sget_headphones) diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-capture.json b/tests/fixtures/ubuntu-22.04/amixer-control-capture.json new file mode 100644 index 00000000..86e7bead --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-capture.json @@ -0,0 +1 @@ +{"control_name": "Capture", "capabilities": ["cvolume", "cswitch"], "limits": {"playback_min": "0", "playback_max": "63"}, "front_left": {"playback_value": "63", "percentage": "100%", "dB": "30.00dB", "status": "on"}, "front_right": {"playback_value": "63", "percentage": "100%", "dB": "30.00dB", "status": "on"}} \ No newline at end of file diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-capture.out b/tests/fixtures/ubuntu-22.04/amixer-control-capture.out new file mode 100644 index 00000000..906458e5 --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-capture.out @@ -0,0 +1,6 @@ +Simple mixer control 'Capture',0 + Capabilities: cvolume cswitch + Capture channels: Front Left - Front Right + Limits: Capture 0 - 63 + Front Left: Capture 63 [100%] [30.00dB] [on] + Front Right: Capture 63 [100%] [30.00dB] [on] diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-headphone.json b/tests/fixtures/ubuntu-22.04/amixer-control-headphone.json new file mode 100644 index 00000000..046fa919 --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-headphone.json @@ -0,0 +1 @@ +{"control_name": "Headphone", "capabilities": ["pvolume", "pswitch"], "playback_channels": ["Front Left", "Front Right"], "limits": {"playback_min": "0", "playback_max": "87"}, "front_left": {"playback_value": "0", "percentage": "0%", "dB": "-65.25dB", "status": "off"}, "front_right": {"playback_value": "0", "percentage": "0%", "dB": "-65.25dB", "status": "off"}} \ No newline at end of file diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-headphone.out b/tests/fixtures/ubuntu-22.04/amixer-control-headphone.out new file mode 100644 index 00000000..b83219e0 --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-headphone.out @@ -0,0 +1,7 @@ +Simple mixer control 'Headphone',0 + Capabilities: pvolume pswitch + Playback channels: Front Left - Front Right + Limits: Playback 0 - 87 + Mono: + Front Left: Playback 0 [0%] [-65.25dB] [off] + Front Right: Playback 0 [0%] [-65.25dB] [off] \ No newline at end of file diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-master.json b/tests/fixtures/ubuntu-22.04/amixer-control-master.json new file mode 100644 index 00000000..9fc00835 --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-master.json @@ -0,0 +1 @@ +{"control_name": "Master", "capabilities": ["pvolume", "pvolume-joined", "pswitch", "pswitch-joined"], "playback_channels": ["Mono"], "limits": {"playback_min": "0", "playback_max": "87"}, "mono": {"playback_value": "87", "percentage": "100%", "dB": "0.00dB", "status": "on"}} \ No newline at end of file diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-master.out b/tests/fixtures/ubuntu-22.04/amixer-control-master.out new file mode 100644 index 00000000..e3ff2463 --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-master.out @@ -0,0 +1,5 @@ +Simple mixer control 'Master',0 + Capabilities: pvolume pvolume-joined pswitch pswitch-joined + Playback channels: Mono + Limits: Playback 0 - 87 + Mono: Playback 87 [100%] [0.00dB] [on] \ No newline at end of file diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-speakers.json b/tests/fixtures/ubuntu-22.04/amixer-control-speakers.json new file mode 100644 index 00000000..80364036 --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-speakers.json @@ -0,0 +1 @@ +{"control_name": "Speaker", "capabilities": ["pvolume", "pswitch"], "playback_channels": ["Front Left", "Front Right"], "limits": {"playback_min": "0", "playback_max": "87"}, "front_left": {"playback_value": "87", "percentage": "100%", "dB": "0.00dB", "status": "on"}, "front_right": {"playback_value": "87", "percentage": "100%", "dB": "0.00dB", "status": "on"}} \ No newline at end of file diff --git a/tests/fixtures/ubuntu-22.04/amixer-control-speakers.out b/tests/fixtures/ubuntu-22.04/amixer-control-speakers.out new file mode 100644 index 00000000..29a2bd50 --- /dev/null +++ b/tests/fixtures/ubuntu-22.04/amixer-control-speakers.out @@ -0,0 +1,7 @@ +Simple mixer control 'Speaker',0 + Capabilities: pvolume pswitch + Playback channels: Front Left - Front Right + Limits: Playback 0 - 87 + Mono: + Front Left: Playback 87 [100%] [0.00dB] [on] + Front Right: Playback 87 [100%] [0.00dB] [on] \ No newline at end of file diff --git a/tests/test_amixer.py b/tests/test_amixer.py new file mode 100644 index 00000000..df56d8a3 --- /dev/null +++ b/tests/test_amixer.py @@ -0,0 +1,37 @@ +import unittest +import jc.parsers.amixer +import os +import json + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class AmixerTests(unittest.TestCase): + AMIXER_CMD = 'amixer' + UBUNTU_22_04_TEST_FIXTURES_PATH = f'tests/fixtures/ubuntu-22.04/' + AMIXER_CONTROL_PATH = f'{UBUNTU_22_04_TEST_FIXTURES_PATH}amixer-control-' + TEST_FILES_NAME = [ + f"{AMIXER_CONTROL_PATH}capture", + f'{AMIXER_CONTROL_PATH}headphone', + f'{AMIXER_CONTROL_PATH}master', + f'{AMIXER_CONTROL_PATH}speakers', + ] + + def setUp(self): + self.test_files_out = [f'{file}.out' for file in self.TEST_FILES_NAME] + self.test_files_json = [f'{file}.json' for file in self.TEST_FILES_NAME] + + def test_amixer_sget(self): + for file_out, file_json in zip(self.test_files_out, self.test_files_json): + with open(file_out, 'r') as f: + amixer_sget_raw_output: str = f.read() + with open(file_json, 'r') as f: + expected_amixer_sget_json_output: str = f.read() + expected_amixer_sget_json_map: dict = json.loads(expected_amixer_sget_json_output) + amixer_sget_json_map: dict = jc.parse(self.AMIXER_CMD, amixer_sget_raw_output) + self.assertEqual(amixer_sget_json_map, expected_amixer_sget_json_map) + + + +if __name__ == '__main__': + unittest.main()