1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-07 00:57:22 +02:00

added tests for the amixer sget

This commit is contained in:
Eden Refael
2024-11-28 23:22:32 +02:00
parent f26d28638a
commit 85c9c8e777
10 changed files with 78 additions and 0 deletions

12
test_file.py Normal file
View File

@ -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)

View File

@ -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"}}

View File

@ -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]

View File

@ -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"}}

View File

@ -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]

View File

@ -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"}}

View File

@ -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]

View File

@ -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"}}

View File

@ -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]

37
tests/test_amixer.py Normal file
View File

@ -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()