1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
.github
completions
docs
jc
man
snap
templates
tests
_vendor
fixtures
templates
__init__.py
test_acpi.py
test_airport.py
test_airport_s.py
test_amixer.py
test_apt_cache_show.py
test_apt_get_sqq.py
test_arp.py
test_asciitable.py
test_asciitable_m.py
test_blkid.py
test_bluetoothctl.py
test_cbt.py
test_cef.py
test_cef_s.py
test_certbot.py
test_chage.py
test_cksum.py
test_clf.py
test_clf_s.py
test_crontab.py
test_crontab_u.py
test_csv.py
test_csv_s.py
test_curl_head.py
test_date.py
test_datetime_iso.py
test_debconf_show.py
test_df.py
test_dig.py
test_dir.py
test_dmidecode.py
test_dpkg_l.py
test_du.py
test_efibootmgr.py
test_email_address.py
test_env.py
test_ethtool.py
test_file.py
test_find.py
test_findmnt.py
test_finger.py
test_free.py
test_fstab.py
test_git_log.py
test_git_log_s.py
test_git_ls_remote.py
test_gpg.py
test_group.py
test_gshadow.py
test_hash.py
test_hashsum.py
test_hciconfig.py
test_history.py
test_host.py
test_hosts.py
test_http_headers.py
test_id.py
test_ifconfig.py
test_iftop.py
test_ini.py
test_ini_dup.py
test_iostat.py
test_iostat_s.py
test_ip_address.py
test_ip_route.py
test_ipconfig.py
test_iptables.py
test_iw_scan.py
test_iwconfig.py
test_jar_manifest.py
test_jc.py
test_jc_cli.py
test_jc_lib.py
test_jc_streaming.py
test_jc_utils.py
test_jobs.py
test_jwt.py
test_kv.py
test_kv_dup.py
test_last.py
test_ls.py
test_ls_s.py
test_lsattr.py
test_lsb_release.py
test_lsblk.py
test_lsmod.py
test_lsof.py
test_lspci.py
test_lsusb.py
test_m3u.py
test_mdadm.py
test_mount.py
test_mpstat.py
test_mpstat_s.py
test_needrestart.py
test_netstat.py
test_nmcli.py
test_nsd_control.py
test_ntpq.py
test_openvpn.py
test_os_prober.py
test_os_release.py
test_pacman.py
test_passwd.py
test_path.py
test_path_list.py
test_pci_ids.py
test_pgpass.py
test_pidstat.py
test_pidstat_s.py
test_ping.py
test_ping_s.py
test_pip_list.py
test_pip_show.py
test_pkg_index_apk.py
test_pkg_index_deb.py
test_plist.py
test_postconf.py
test_proc.py
test_proc_buddyinfo.py
test_proc_cmdline.py
test_proc_consoles.py
test_proc_cpuinfo.py
test_proc_crypto.py
test_proc_devices.py
test_proc_diskstats.py
test_proc_driver_rtc.py
test_proc_filesystems.py
test_proc_interrupts.py
test_proc_iomem.py
test_proc_ioports.py
test_proc_loadavg.py
test_proc_locks.py
test_proc_meminfo.py
test_proc_modules.py
test_proc_mtrr.py
test_proc_net_arp.py
test_proc_net_dev.py
test_proc_net_dev_mcast.py
test_proc_net_if_inet6.py
test_proc_net_igmp.py
test_proc_net_igmp6.py
test_proc_net_ipv6_route.py
test_proc_net_netlink.py
test_proc_net_netstat.py
test_proc_net_packet.py
test_proc_net_protocols.py
test_proc_net_route.py
test_proc_net_tcp.py
test_proc_net_unix.py
test_proc_pagetypeinfo.py
test_proc_partitions.py
test_proc_pid_fdinfo.py
test_proc_pid_io.py
test_proc_pid_maps.py
test_proc_pid_mountinfo.py
test_proc_pid_numa_maps.py
test_proc_pid_smaps.py
test_proc_pid_stat.py
test_proc_pid_statm.py
test_proc_pid_status.py
test_proc_slabinfo.py
test_proc_softirqs.py
test_proc_stat.py
test_proc_swaps.py
test_proc_uptime.py
test_proc_version.py
test_proc_vmallocinfo.py
test_proc_vmstat.py
test_proc_zoneinfo.py
test_ps.py
test_resolve_conf.py
test_route.py
test_rpm_qai.py
test_rsync.py
test_rsync_s.py
test_semver.py
test_sfdisk.py
test_shadow.py
test_srt.py
test_ss.py
test_ssh_conf.py
test_sshd_conf.py
test_stat.py
test_stat_s.py
test_swapon.py
test_sysctl.py
test_syslog.py
test_syslog_bsd.py
test_syslog_bsd_s.py
test_syslog_s.py
test_systemctl.py
test_systemctl_lj.py
test_systemctl_ls.py
test_systemctl_luf.py
test_systeminfo.py
test_time.py
test_timedatectl.py
test_timestamp.py
test_toml.py
test_top.py
test_top_s.py
test_tracepath.py
test_traceroute.py
test_tune2fs.py
test_udevadm.py
test_ufw.py
test_ufw_appinfo.py
test_uname.py
test_update_alt_gs.py
test_update_alt_q.py
test_upower.py
test_uptime.py
test_url.py
test_ver.py
test_veracrypt.py
test_vmstat.py
test_vmstat_s.py
test_w.py
test_wc.py
test_wg_show.py
test_who.py
test_x509_cert.py
test_x509_csr.py
test_xml.py
test_xrandr.py
test_yaml.py
test_zipinfo.py
test_zpool_iostat.py
test_zpool_status.py
utils_for_test.py
.gitignore
CHANGELOG
CONTRIBUTING.md
EXAMPLES.md
LICENSE.md
MANIFEST.in
README-snap.md
README.md
_config.yml
build-completions.py
build-package.sh
doc2md.py
docgen.sh
install.sh
mangen.py
pypi-upload.sh
readmegen.py
requirements.txt
runtests-missing-libs.sh
runtests.sh
setup.cfg
setup.py
updatedocs.sh
Kelly Brazil c8720b259c optimize tests
2022-09-23 14:02:27 -07:00

83 lines
3.4 KiB
Python

import os
import unittest
import json
import jc.parsers.top
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/top-b-n3.out'), 'r', encoding='utf-8') as f:
centos_7_7_top_b_n3 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/top-b-n1-gib.out'), 'r', encoding='utf-8') as f:
centos_7_7_top_b_n1_gib = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/top-b-n1-gib-allfields-w.out'), 'r', encoding='utf-8') as f:
centos_7_7_top_b_n1_gib_allfields_w = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.10/top-b-n1.out'), 'r', encoding='utf-8') as f:
ubuntu_20_10_top_b_n1 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.10/top-b-allfields.out'), 'r', encoding='utf-8') as f:
ubuntu_20_10_top_b_allfields = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/top-b-n3.json'), 'r', encoding='utf-8') as f:
centos_7_7_top_b_n3_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/top-b-n1-gib.json'), 'r', encoding='utf-8') as f:
centos_7_7_top_b_n1_gib_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/top-b-n1-gib-allfields-w.json'), 'r', encoding='utf-8') as f:
centos_7_7_top_b_n1_gib_allfields_w_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.10/top-b-n1.json'), 'r', encoding='utf-8') as f:
ubuntu_20_10_top_b_n1_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.10/top-b-allfields.json'), 'r', encoding='utf-8') as f:
ubuntu_20_10_top_b_allfields_json = json.loads(f.read())
def test_top_nodata(self):
"""
Test 'top -b' with no data
"""
self.assertEqual(jc.parsers.top.parse('', quiet=True), [])
def test_top_centos_7_7(self):
"""
Test 'top -b -n 3' on Centos 7.7
"""
self.assertEqual(jc.parsers.top.parse(self.centos_7_7_top_b_n3, quiet=True), self.centos_7_7_top_b_n3_json)
def test_top_gib_centos_7_7(self):
"""
Test 'top -b -n 1' with units as GiB on Centos 7.7
"""
self.assertEqual(jc.parsers.top.parse(self.centos_7_7_top_b_n1_gib, quiet=True), self.centos_7_7_top_b_n1_gib_json)
def test_top_gib_allfields_wide_centos_7_7(self):
"""
Test 'top -b -n 1' with units as GiB, all fields selected, and wide output on Centos 7.7
"""
self.assertEqual(jc.parsers.top.parse(self.centos_7_7_top_b_n1_gib_allfields_w, quiet=True), self.centos_7_7_top_b_n1_gib_allfields_w_json)
def test_top_ubuntu_20_10(self):
"""
Test 'top -b -n 1' with units as MiB on Ubuntu 20.10
"""
self.assertEqual(jc.parsers.top.parse(self.ubuntu_20_10_top_b_n1, quiet=True), self.ubuntu_20_10_top_b_n1_json)
def test_top_allfields_ubuntu_20_10(self):
"""
Test 'top -b -n 1' with units as MiB and all fields on Ubuntu 20.10
"""
self.assertEqual(jc.parsers.top.parse(self.ubuntu_20_10_top_b_allfields, quiet=True), self.ubuntu_20_10_top_b_allfields_json)
if __name__ == '__main__':
unittest.main()