mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
fix bug when no slaves are present
This commit is contained in:
@ -241,11 +241,13 @@ def parse(
|
|||||||
if not 'alternatives' in raw_output:
|
if not 'alternatives' in raw_output:
|
||||||
raw_output['alternatives'] = []
|
raw_output['alternatives'] = []
|
||||||
|
|
||||||
|
if alt_obj:
|
||||||
if slaves:
|
if slaves:
|
||||||
alt_obj['slaves'] = slaves
|
alt_obj['slaves'] = slaves
|
||||||
raw_output['alternatives'].append(alt_obj)
|
|
||||||
slaves = []
|
slaves = []
|
||||||
|
|
||||||
|
raw_output['alternatives'].append(alt_obj)
|
||||||
|
|
||||||
alt_obj = {"alternative": line_list[1]}
|
alt_obj = {"alternative": line_list[1]}
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
1
tests/fixtures/generic/update-alternatives-query2.json
vendored
Normal file
1
tests/fixtures/generic/update-alternatives-query2.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"name":"php-fpm.sock","link":"/run/php/php-fpm.sock","status":"auto","best":"/run/php/php8.1-fpm.sock","value":"/run/php/php8.1-fpm.sock","alternatives":[{"alternative":"/run/php/php7.4-fpm.sock","priority":74},{"alternative":"/run/php/php8.0-fpm.sock","priority":80},{"alternative":"/run/php/php8.1-fpm.sock","priority":81}]}
|
14
tests/fixtures/generic/update-alternatives-query2.out
vendored
Normal file
14
tests/fixtures/generic/update-alternatives-query2.out
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Name: php-fpm.sock
|
||||||
|
Link: /run/php/php-fpm.sock
|
||||||
|
Status: auto
|
||||||
|
Best: /run/php/php8.1-fpm.sock
|
||||||
|
Value: /run/php/php8.1-fpm.sock
|
||||||
|
|
||||||
|
Alternative: /run/php/php7.4-fpm.sock
|
||||||
|
Priority: 74
|
||||||
|
|
||||||
|
Alternative: /run/php/php8.0-fpm.sock
|
||||||
|
Priority: 80
|
||||||
|
|
||||||
|
Alternative: /run/php/php8.1-fpm.sock
|
||||||
|
Priority: 81
|
@ -13,10 +13,17 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/update-alternatives-query.out'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/update-alternatives-query.out'), 'r', encoding='utf-8') as f:
|
||||||
self.update_alternatives_query = f.read()
|
self.update_alternatives_query = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/update-alternatives-query2.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.update_alternatives_query2 = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/update-alternatives-query.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/update-alternatives-query.json'), 'r', encoding='utf-8') as f:
|
||||||
self.update_alternatives_query_json = json.loads(f.read())
|
self.update_alternatives_query_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/update-alternatives-query2.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.update_alternatives_query2_json = json.loads(f.read())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_update_alt_q_nodata(self):
|
def test_update_alt_q_nodata(self):
|
||||||
"""
|
"""
|
||||||
@ -30,6 +37,12 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.update_alt_q.parse(self.update_alternatives_query, quiet=True), self.update_alternatives_query_json)
|
self.assertEqual(jc.parsers.update_alt_q.parse(self.update_alternatives_query, quiet=True), self.update_alternatives_query_json)
|
||||||
|
|
||||||
|
def test_update_alt_q_no_slaves(self):
|
||||||
|
"""
|
||||||
|
Test 'update-alternatives --query' with no slaves in output
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.update_alt_q.parse(self.update_alternatives_query2, quiet=True), self.update_alternatives_query2_json)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user