1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/test_amixer.py

71 lines
3.3 KiB
Python
Raw Normal View History

created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
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'{THIS_DIR}/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]
self.test_files_processed_json = [f'{file}-processed.json' for file in self.TEST_FILES_NAME]
2024-12-20 16:31:38 -08:00
def test_amixer_sget_nodata(self):
"""
Test 'amixer' with no data
"""
self.assertEqual(jc.parsers.amixer.parse('', quiet=True), {})
created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
def test_amixer_sget(self):
for file_out, file_json, file_processed_json in zip(self.test_files_out, self.test_files_json,
self.test_files_processed_json):
with open(file_out, 'r') as f:
amixer_sget_raw_output = f.read()
created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
with open(file_json, 'r') as f:
expected_amixer_sget_json_output = f.read()
expected_amixer_sget_json_map = json.loads(expected_amixer_sget_json_output)
created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
with open(file_processed_json, 'r') as f:
expected_amixer_sget_processed_json_output = f.read()
expected_amixer_sget_processed_json_map = json.loads(expected_amixer_sget_processed_json_output)
created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
# Tests for raw=True
amixer_sget_json_map = jc.parse(self.AMIXER_CMD, amixer_sget_raw_output, raw=True,
created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
quiet=True)
self.assertEqual(amixer_sget_json_map, expected_amixer_sget_json_map)
# Tests for raw=False process
amixer_sget_json_processed_map = jc.parse(self.AMIXER_CMD, amixer_sget_raw_output, raw=False,
created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
quiet=True)
self.assertEqual(amixer_sget_json_processed_map, expected_amixer_sget_processed_json_map)
2025-03-31 16:50:46 -07:00
def test_amixer_missing_db(self):
data = '''Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 55039 [84%] [on]
Front Right: Playback 54383 [83%] [on]
Simple mixer control 'Capture',0
Capabilities: cvolume cswitch cswitch-joined
Capture channels: Front Left - Front Right
Limits: Capture 0 - 65536
Front Left: Capture 24672 [38%] [on]
Front Right: Capture 24672 [38%] [on]'''
expected = {"control_name":"Master","capabilities":["cvolume","cswitch","cswitch-joined"],"playback_channels":["Front Left","Front Right"],"limits":{"playback_min":0,"playback_max":65536},"front_left":{"playback_value":24672,"percentage":38,"db":0.0,"status":True},"front_right":{"playback_value":24672,"percentage":38,"db":0.0,"status":True}}
self.assertEqual(expected, jc.parsers.amixer.parse(data, quiet=True))
created the amixer sget command parser - READY FOR REVIEW (#616) * created the amixer first skeleton * push testing and integrate this commit and branch with issue: #591 * #591 checks the input data with jc utils * created the data parser of the sget control of the amixer sget <controller> command. * test commit - just for tests * another test commit * another test commit * created a dedicated pseudo algorithm for the amixer sget and tried various of strings. * orginized the docstring with general explanation about the tool and the amixer tool output and algorithm of the input parsing and input examples. * created raw implementation, but it's raw either or either. * orginized the content inside the amixer parser * removed endpoint name * added amixer to the jc parser in lib * more explanations * added tests for the amixer sget * added tests for the amixer sget * fine versioning fix * created docstring+another explanations seperated. * created the amixer parser docu * added the amixer in alphabet order to the json convert lib * Fix PEP 8: E302 violation as part of boy scout principle * deleted not necessary file * fixed the spaces between sections in the amixer description * resolved commits such as amixer module docstring and preperations for parser for raw=False. * Revert "Fix PEP 8: E302 violation as part of boy scout principle" This reverts commit 241d1a1c630bd21ef7bd443d55a3eb149d77c943. * created the dedicated _process for raw=False * created the dedicated _process for raw=False * added tests for the _process raw=False. * changed keys to be lowercase snake-case - Change 'dB' to 'db' * added more dB -> db changes and used int convertor of the jc utils --------- Co-authored-by: EdenRafael <eden.refael@kazuar.com> Co-authored-by: Eden Refael <edeenraf@hotmail.com> Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2024-12-21 01:06:38 +02:00
if __name__ == '__main__':
unittest.main()