1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
import os
import json
import unittest
import jc.parsers.free
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/free.out'), 'r', encoding='utf-8') as f:
centos_7_7_free = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/free.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_free = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/free-h.out'), 'r', encoding='utf-8') as f:
centos_7_7_free_h = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/free-h.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_free_h = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/free-w.out'), 'r', encoding='utf-8') as f:
centos_7_7_free_w = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/free-w.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_free_w = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/free.json'), 'r', encoding='utf-8') as f:
centos_7_7_free_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/free.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_free_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/free-h.json'), 'r', encoding='utf-8') as f:
centos_7_7_free_h_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/free-h.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_free_h_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/free-w.json'), 'r', encoding='utf-8') as f:
centos_7_7_free_w_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/free-w.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_free_w_json = json.loads(f.read())
def test_free_nodata(self):
"""
Test 'free' with no data
"""
self.assertEqual(jc.parsers.free.parse('', quiet=True), [])
def test_free_centos_7_7(self):
"""
Test 'free' on Centos 7.7
"""
self.assertEqual(jc.parsers.free.parse(self.centos_7_7_free, quiet=True), self.centos_7_7_free_json)
def test_free_ubuntu_18_4(self):
"""
Test 'free' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.free.parse(self.ubuntu_18_4_free, quiet=True), self.ubuntu_18_4_free_json)
def test_free_h_centos_7_7(self):
"""
Test 'free -h' on Centos 7.7
"""
self.assertEqual(jc.parsers.free.parse(self.centos_7_7_free_h, quiet=True), self.centos_7_7_free_h_json)
def test_free_h_ubuntu_18_4(self):
"""
Test 'free -h' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.free.parse(self.ubuntu_18_4_free_h, quiet=True), self.ubuntu_18_4_free_h_json)
def test_free_w_centos_7_7(self):
"""
Test 'free -w' on Centos 7.7
"""
self.assertEqual(jc.parsers.free.parse(self.centos_7_7_free_w, quiet=True), self.centos_7_7_free_w_json)
def test_free_w_ubuntu_18_4(self):
"""
Test 'free -w' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.free.parse(self.ubuntu_18_4_free_w, quiet=True), self.ubuntu_18_4_free_w_json)
if __name__ == '__main__':
unittest.main()
|