From f1e0cec9d65e6f3c5b6c21d0bf1ab796eaddc38a Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 4 Dec 2023 14:01:30 -0800 Subject: [PATCH] add apkindex parser --- CHANGELOG | 4 +- README.md | 1 + completions/jc_bash_completion.sh | 2 +- completions/jc_zsh_completion.sh | 3 +- docs/parsers/apkindex.md | 126 ++++++++++++++++++++++++++++++ jc/parsers/apkindex.py | 64 ++++++++------- man/jc.1 | 10 +-- tests/test_apkindex.py | 43 +++++++--- 8 files changed, 205 insertions(+), 48 deletions(-) create mode 100644 docs/parsers/apkindex.md diff --git a/CHANGELOG b/CHANGELOG index b845b4b5..5859fd1f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,12 +1,14 @@ jc changelog 20231128 v1.24.0 +- Add `apkindex` parser for Alpine Linux Package Index files - Add `deb-packages-index` parser for Debian/Ubuntu Package Index files - Add `debconf-show` command parser - Add `swapon` command parser - Add `tune2fs` command parser -- Remove `iso-datetime` parser (use `datetime-iso` instead) +- Remove `iso-datetime` parser deprecated since v1.22.1. (use `datetime-iso` instead) - Update timezone change in Github Actions for node v16 requirement +- Add Python 3.12 tests to Github Actions - Refactor `acpi` command parser for code cleanup - Fix `iptables` parser for cases where the `target` field is blank in a rule - Fix `vmstat` parsers for some cases where wide output is used diff --git a/README.md b/README.md index c74b6233..aba68cd3 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,7 @@ option. | `--acpi` | `acpi` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/acpi) | | `--airport` | `airport -I` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport) | | `--airport-s` | `airport -s` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport_s) | +| `--apkindex` | Alpine Linux Package Index file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/apkindex) | | `--arp` | `arp` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/arp) | | `--asciitable` | ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable) | | `--asciitable-m` | multi-line ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable_m) | diff --git a/completions/jc_bash_completion.sh b/completions/jc_bash_completion.sh index c0e8b7ab..d27ec00a 100644 --- a/completions/jc_bash_completion.sh +++ b/completions/jc_bash_completion.sh @@ -4,7 +4,7 @@ _jc() jc_about_options jc_about_mod_options jc_help_options jc_special_options jc_commands=(acpi airport arp blkid bluetoothctl cbt certbot chage cksum crontab date debconf-show df dig dmidecode dpkg du env file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool) - jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --date --datetime-iso --deb-packages-index --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) + jc_parsers=(--acpi --airport --airport-s --apkindex --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --date --datetime-iso --deb-packages-index --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) jc_options=(--force-color -C --debug -d --monochrome -m --meta-out -M --pretty -p --quiet -q --raw -r --unbuffer -u --yaml-out -y) jc_about_options=(--about -a) jc_about_mod_options=(--pretty -p --yaml-out -y --monochrome -m --force-color -C) diff --git a/completions/jc_zsh_completion.sh b/completions/jc_zsh_completion.sh index 3f64c20a..a04dcc82 100644 --- a/completions/jc_zsh_completion.sh +++ b/completions/jc_zsh_completion.sh @@ -115,11 +115,12 @@ _jc() { 'zipinfo:run "zipinfo" command with magic syntax.' 'zpool:run "zpool" command with magic syntax.' ) - jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --date --datetime-iso --deb-packages-index --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) + jc_parsers=(--acpi --airport --airport-s --apkindex --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --date --datetime-iso --deb-packages-index --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status) jc_parsers_describe=( '--acpi:`acpi` command parser' '--airport:`airport -I` command parser' '--airport-s:`airport -s` command parser' + '--apkindex:Alpine Linux Package Index file parser' '--arp:`arp` command parser' '--asciitable:ASCII and Unicode table parser' '--asciitable-m:multi-line ASCII and Unicode table parser' diff --git a/docs/parsers/apkindex.md b/docs/parsers/apkindex.md new file mode 100644 index 00000000..e860a1a8 --- /dev/null +++ b/docs/parsers/apkindex.md @@ -0,0 +1,126 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.apkindex + +jc - JSON Convert Alpine Linux Package Index files + +Usage (cli): + + $ jc --apkindex < APKINDEX + +Usage (module): + + import jc + result = jc.parse('apkindex', apkindex_output) + +Schema: + + [ + { + "checksum": string, + "package": string, + "version": string, + "architecture": string, + "package_size": integer, + "installed_size": integer, + "description": string, + "url": string, + "license": string, + "origin": string, + "maintainer": { + "name": string, + "email": string, + }, + "build_time": integer, + "commit": string, + "provider_priority": string, + "dependencies": [ + string + ], + "provides": [ + string + ], + "install_if": [ + string + ], + } + ] + +Example: + + $ jc --apkindex < APKINDEX + [ + { + "checksum": "Q1znBl9k+RKgY6gl5Eg3iz73KZbLY=", + "package": "yasm", + "version": "1.3.0-r4", + "architecture": "x86_64", + "package_size": 772109, + "installed_size": 1753088, + "description": "A rewrite of NASM to allow for multiple synta...", + "url": "http://www.tortall.net/projects/yasm/", + "license": "BSD-2-Clause", + "origin": "yasm", + "maintainer": { + "name": "Natanael Copa", + "email": "ncopa@alpinelinux.org" + }, + "build_time": 1681228881, + "commit": "84a227baf001b6e0208e3352b294e4d7a40e93de", + "dependencies": [ + "so:libc.musl-x86_64.so.1" + ], + "provides": [ + "cmd:vsyasm=1.3.0-r4", + "cmd:yasm=1.3.0-r4", + "cmd:ytasm=1.3.0-r4" + ] + } + ] + + $ jc --apkindex --raw < APKINDEX + [ + { + "C": "Q1znBl9k+RKgY6gl5Eg3iz73KZbLY=", + "P": "yasm", + "V": "1.3.0-r4", + "A": "x86_64", + "S": "772109", + "I": "1753088", + "T": "A rewrite of NASM to allow for multiple syntax supported...", + "U": "http://www.tortall.net/projects/yasm/", + "L": "BSD-2-Clause", + "o": "yasm", + "m": "Natanael Copa ", + "t": "1681228881", + "c": "84a227baf001b6e0208e3352b294e4d7a40e93de", + "D": "so:libc.musl-x86_64.so.1", + "p": "cmd:vsyasm=1.3.0-r4 cmd:yasm=1.3.0-r4 cmd:ytasm=1.3.0-r4" + }, + ] + + + +### parse + +```python +def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] +``` + +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, darwin, cygwin, win32, aix, freebsd + +Version 1.0 by Roey Darwish Dror (roey.ghost@gmail.com) diff --git a/jc/parsers/apkindex.py b/jc/parsers/apkindex.py index 1e644edb..e1b83b73 100644 --- a/jc/parsers/apkindex.py +++ b/jc/parsers/apkindex.py @@ -1,4 +1,4 @@ -"""jc - JSON Convert `APKINDEX` files +"""jc - JSON Convert Alpine Linux Package Index files Usage (cli): @@ -7,32 +7,38 @@ Usage (cli): Usage (module): import jc - result = jc.parse('apkindex', apkindex) + result = jc.parse('apkindex', apkindex_output) Schema: [ { - "checksum": string, - "package": string, - "version": string, - "architecture": string, - "package_size": integer, - "installed_size": integer, - "description": string, - "url": string, - "license": string, - "origin": string, + "checksum": string, + "package": string, + "version": string, + "architecture": string, + "package_size": integer, + "installed_size": integer, + "description": string, + "url": string, + "license": string, + "origin": string, "maintainer": { - "name": string, - "email": string, + "name": string, + "email": string, }, - "build_time": integer, - "commit": string, - "provider_priority": string, - "dependencies": [string], - "provides": [string], - "install_if": [string], + "build_time": integer, + "commit": string, + "provider_priority": string, + "dependencies": [ + string + ], + "provides": [ + string + ], + "install_if": [ + string + ], } ] @@ -47,7 +53,7 @@ Example: "architecture": "x86_64", "package_size": 772109, "installed_size": 1753088, - "description": "A rewrite of NASM to allow for multiple syntax supported (NASM, TASM, GAS, etc.)", + "description": "A rewrite of NASM to allow for multiple synta...", "url": "http://www.tortall.net/projects/yasm/", "license": "BSD-2-Clause", "origin": "yasm", @@ -77,7 +83,7 @@ Example: "A": "x86_64", "S": "772109", "I": "1753088", - "T": "A rewrite of NASM to allow for multiple syntax supported (NASM, TASM, GAS, etc.)", + "T": "A rewrite of NASM to allow for multiple syntax supported...", "U": "http://www.tortall.net/projects/yasm/", "L": "BSD-2-Clause", "o": "yasm", @@ -96,13 +102,12 @@ import jc.utils class info: """Provides parser metadata (version, author, etc.)""" - version = "1.0" - description = "APKINDEX parser" + description = "Alpine Linux Package Index file parser" author = "Roey Darwish Dror" author_email = "roey.ghost@gmail.com" compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'] - tags = ['standard', 'file', 'string', 'binary'] + tags = ['standard', 'file', 'string'] __version__ = info.version @@ -125,7 +130,7 @@ _KEY = { "k": "provider_priority", "D": "dependencies", "p": "provides", - "i": "install_if", + "i": "install_if" } def _value(key: str, value: str) -> Union[str, int, List[str], Dict[str, str]]: @@ -155,8 +160,9 @@ def _value(key: str, value: str) -> Union[str, int, List[str], Dict[str, str]]: else: return {'name': value} - return value + + def _process(proc_data: List[Dict]) -> List[Dict]: """ Final processing to conform to the schema. @@ -184,14 +190,14 @@ def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]: Returns: - Dictionary. Raw or processed structured data. + List of Dictionaries. Raw or processed structured data. """ jc.utils.compatibility(__name__, info.compatible, quiet) jc.utils.input_type_check(data) raw_output: List[dict] = [] - package = {} + package: Dict = {} if jc.utils.has_data(data): lines = iter(data.splitlines()) for line in lines: diff --git a/man/jc.1 b/man/jc.1 index 8a627407..20a31933 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -52,6 +52,11 @@ Parsers: \fB--airport-s\fP `airport -s` command parser +.TP +.B +\fB--apkindex\fP +Alpine Linux Package Index file parser + .TP .B \fB--arp\fP @@ -332,11 +337,6 @@ IPv4 and IPv6 Address string parser \fB--ip-route\fP `ip route` command parser -.TP -.B -\fB--iso-datetime\fP -Deprecated - please use datetime-iso - .TP .B \fB--iw-scan\fP diff --git a/tests/test_apkindex.py b/tests/test_apkindex.py index a0a440f8..3ef55e78 100644 --- a/tests/test_apkindex.py +++ b/tests/test_apkindex.py @@ -10,30 +10,51 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) class Apkindex(unittest.TestCase): f_in: Dict = {} f_json: Dict = {} - f_raw: Dict = {} @classmethod def setUpClass(cls): fixtures = { - "normal": ("fixtures/generic/apkindex", "fixtures/generic/apkindex.json", "fixtures/generic/apkindex.raw.json"), + 'normal': ( + 'fixtures/generic/apkindex', + 'fixtures/generic/apkindex.json'), + 'raw': ( + 'fixtures/generic/apkindex', + 'fixtures/generic/apkindex.raw.json') } for file, filepaths in fixtures.items(): - with open(os.path.join(THIS_DIR, filepaths[0]), "r", encoding="utf-8") as a, open( - os.path.join(THIS_DIR, filepaths[1]), "r", encoding="utf-8" - ) as b, open( - os.path.join(THIS_DIR, filepaths[1]), "r", encoding="utf-8" - ) as c: + with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \ + open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b: cls.f_in[file] = a.read() cls.f_json[file] = json.loads(b.read()) - cls.f_raw[file] = json.loads(c.read()) + + + def test_apkindex_nodata(self): + """ + Test 'apkindex' with no data + """ + self.assertEqual(parse('', quiet=True), []) + def test_apkindex(self): """ - Test 'apkindex' + Test 'apkindex' normal output """ - f = "normal" - self.assertEqual(parse(self.f_in[f], quiet=True), self.f_json[f]) + self.assertEqual( + parse(self.f_in['normal'], quiet=True), + self.f_json['normal'] + ) + + + def test_apkindex_raw(self): + """ + Test 'apkindex' raw output + """ + self.assertEqual( + parse(self.f_in['raw'], quiet=True, raw=True), + self.f_json['raw'] + ) + if __name__ == "__main__": unittest.main()