1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +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_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_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
jc/tests/test_upower.py

95 lines
3.9 KiB
Python
Raw Normal View History

2021-03-24 21:24:25 -07:00
import os
import json
import unittest
import jc.parsers.upower
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
2022-09-23 14:02:27 -07:00
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-i.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_upower_i = f.read()
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_upower_d = f.read()
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d-clocale.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_upower_d_clocale = f.read()
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-utc.out'), 'r', encoding='utf-8') as f:
generic_upower_i_utc = f.read()
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-non-utc.out'), 'r', encoding='utf-8') as f:
generic_upower_i_non_utc = f.read()
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-c-locale.out'), 'r', encoding='utf-8') as f:
generic_upower_i_c_locale = f.read()
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-i.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_upower_i_json = json.loads(f.read())
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_upower_d_json = json.loads(f.read())
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d-clocale.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_upower_d_clocale_json = json.loads(f.read())
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-utc.json'), 'r', encoding='utf-8') as f:
generic_upower_i_utc_json = json.loads(f.read())
2021-03-24 21:24:25 -07:00
2022-09-23 14:02:27 -07:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-non-utc.json'), 'r', encoding='utf-8') as f:
generic_upower_i_non_utc_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-c-locale.json'), 'r', encoding='utf-8') as f:
generic_upower_i_c_locale_json = json.loads(f.read())
2021-03-24 21:24:25 -07:00
def test_upower_nodata(self):
"""
Test 'upower' with no data
"""
self.assertEqual(jc.parsers.upower.parse('', quiet=True), [])
def test_upower_i_ubuntu_18_4(self):
"""
Test 'upower -i' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.upower.parse(self.ubuntu_18_4_upower_i, quiet=True), self.ubuntu_18_4_upower_i_json)
def test_upower_d_ubuntu_18_4(self):
"""
Test 'upower -d' on Ubuntu 18.4 using LANG=en_US.UTF-8
"""
self.assertEqual(jc.parsers.upower.parse(self.ubuntu_18_4_upower_d, quiet=True), self.ubuntu_18_4_upower_d_json)
def test_upower_d_clocale_ubuntu_18_4(self):
"""
Test 'upower -d' on Ubuntu 18.4 using LANG=C
"""
self.assertEqual(jc.parsers.upower.parse(self.ubuntu_18_4_upower_d, quiet=True), self.ubuntu_18_4_upower_d_json)
def test_upower_i_utc_generic(self):
"""
Test 'upower -i' with utc time output
"""
self.assertEqual(jc.parsers.upower.parse(self.generic_upower_i_utc, quiet=True), self.generic_upower_i_utc_json)
def test_upower_i_non_utc_generic(self):
"""
Test 'upower -i' with non-utc time output
"""
self.assertEqual(jc.parsers.upower.parse(self.generic_upower_i_non_utc, quiet=True), self.generic_upower_i_non_utc_json)
def test_upower_i_c_locale(self):
"""
Test 'upower -i' with LANG=C time output
"""
self.assertEqual(jc.parsers.upower.parse(self.generic_upower_i_c_locale, quiet=True), self.generic_upower_i_c_locale_json)
if __name__ == '__main__':
unittest.main()