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

add apt-get-sqq parser tests

This commit is contained in:
Kelly Brazil
2024-03-01 14:25:33 -08:00
parent 527b5ab5c5
commit 5ac36befe2
5 changed files with 377 additions and 8 deletions

201
docs/parsers/apt_get_sqq.md Normal file
View File

@ -0,0 +1,201 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.apt_get_sqq"></a>
# jc.parsers.apt\_get\_sqq
jc - JSON Convert `apt-get -sqq` command output parser
Requires the `-sqq` options in `apt-get`.
Usage (cli):
$ apt-get -sqq | jc --apt-get-sqq
or
$ jc apt-get -sqq
Usage (module):
import jc
result = jc.parse('apt_get_sqq', apt_get_sqq_command_output)
Schema:
[
{
"operation": string, # configure, remove, or unpack
"package": string,
"broken": string/null,
"proposed_pkg_ver": string,
"existing_src": string/null,
"architecture": string
}
]
Examples:
$ apt-get -sqq | jc --apt-get-sqq -p
[
{
"operation": "unpack",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "unpack",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "configure",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "remove",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "unpack",
"package": "base-files",
"broken": "10.3+deb10u4",
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "configure",
"package": "base-files",
"broken": null,
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "unpack",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "configure",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
}
]
$ apt-get -sqq | jc --apt-get-sqq -p -r
[
{
"operation": "Inst",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Inst",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Conf",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Remv",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Inst",
"package": "base-files",
"broken": "10.3+deb10u4",
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "Conf",
"package": "base-files",
"broken": null,
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "Inst",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Conf",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
}
]
<a id="jc.parsers.apt_get_sqq.parse"></a>
### parse
```python
def parse(data: str,
raw: bool = False,
quiet: bool = False) -> List[JSONDictType]
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
### Parser Information
Compatibility: linux
Source: [`jc/parsers/apt_get_sqq.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/apt_get_sqq.py)
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@ -19,22 +19,152 @@ Schema:
[ [
{ {
"operation": string, # configure, remove, or unpack "operation": string, # configure, remove, or unpack
"package": string, "package": string,
"broken": string or null, "broken": string/null,
"proposed_pkg_ver": string, "proposed_pkg_ver": string,
"existing_src": string, "existing_src": string/null,
"architecture": string "architecture": string
} }
] ]
Examples: Examples:
$ foo | jc --foo -p $ apt-get -sqq | jc --apt-get-sqq -p
[] [
{
"operation": "unpack",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "unpack",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "configure",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "remove",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "unpack",
"package": "base-files",
"broken": "10.3+deb10u4",
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "configure",
"package": "base-files",
"broken": null,
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "unpack",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "configure",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
}
]
$ foo | jc --foo -p -r $ apt-get -sqq | jc --apt-get-sqq -p -r
[] [
{
"operation": "Inst",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Inst",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Conf",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Remv",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Inst",
"package": "base-files",
"broken": "10.3+deb10u4",
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "Conf",
"package": "base-files",
"broken": null,
"proposed_pkg_ver": "10.3+deb10u13 Debian:10.13/oldstable",
"existing_src": null,
"architecture": "amd64"
},
{
"operation": "Inst",
"package": "dpkg",
"broken": "1.19.7",
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
},
{
"operation": "Conf",
"package": "dpkg",
"broken": null,
"proposed_pkg_ver": "1.19.8 Debian:10.13/oldstable",
"existing_src": "Debian-Security:10/oldstable",
"architecture": "amd64"
}
]
""" """
import re import re
from typing import List, Dict from typing import List, Dict
@ -108,7 +238,7 @@ def parse(
# Inst dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64]) # Inst dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64])
# | | | | | \architecture # | | | | | \architecture
# | | | | \existing_src # | | | | \existing_src (optional)
# | | | \proposed_pkg_ver # | | | \proposed_pkg_ver
# | | \broken (optional) # | | \broken (optional)
# | \package # | \package

View File

@ -0,0 +1 @@
[{"operation":"unpack","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"unpack","package":"dpkg","broken":null,"proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"configure","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"remove","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"unpack","package":"base-files","broken":"10.3+deb10u4","proposed_pkg_ver":"10.3+deb10u13 Debian:10.13/oldstable","existing_src":null,"architecture":"amd64"},{"operation":"configure","package":"base-files","broken":null,"proposed_pkg_ver":"10.3+deb10u13 Debian:10.13/oldstable","existing_src":null,"architecture":"amd64"},{"operation":"unpack","package":"dpkg","broken":"1.19.7","proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"},{"operation":"configure","package":"dpkg","broken":null,"proposed_pkg_ver":"1.19.8 Debian:10.13/oldstable","existing_src":"Debian-Security:10/oldstable","architecture":"amd64"}]

View File

@ -0,0 +1,9 @@
Inst dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64])
Inst dpkg (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64])
Conf dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64])
Remv dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64])
Inst base-files [10.3+deb10u4] (10.3+deb10u13 Debian:10.13/oldstable [amd64])
Conf base-files (10.3+deb10u13 Debian:10.13/oldstable [amd64])
Inst dpkg [1.19.7] (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64])
Conf dpkg (1.19.8 Debian:10.13/oldstable, Debian-Security:10/oldstable [amd64])

28
tests/test_apt_get_sqq.py Normal file
View File

@ -0,0 +1,28 @@
import unittest
from tests import utils_for_test as test_utils
# Execute these steps for standard tests:
# - Save this file as `test_{parser_name}.py` since the helper methods extract parser names from the filename.
# - Organize fixtures in `tests/fixtures` for optimal structure.
# - Format fixtures as follows (using double dashes):
# - `{parser_name}--{some_test_description}.out` for command output.
# - `{parser_name}--{some_test_description}.json` for expected JSON after parsing.
class MyTests(unittest.TestCase):
def test_apt_get_sqq_nodata(self):
"""
Test 'apt-get -sqq' with no data
"""
test_utils.run_no_data(self, __file__, [])
def test_apt_get_sqq_all_fixtures(self):
"""
Test 'apt-get -sqq' with various fixtures
"""
test_utils.run_all_fixtures(self, __file__)
if __name__ == '__main__':
unittest.main()