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

71 lines
2.5 KiB
Python
Raw Normal View History

2019-12-16 13:52:42 -08:00
import os
import json
import unittest
import jc.parsers.du
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/du.out'), 'r', encoding='utf-8') as f:
2019-12-16 13:52:42 -08:00
self.centos_7_7_du = f.read()
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/du.out'), 'r', encoding='utf-8') as f:
2019-12-16 14:27:55 -08:00
self.ubuntu_18_4_du = f.read()
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/du.out'), 'r', encoding='utf-8') as f:
2019-12-16 14:27:55 -08:00
self.osx_10_11_6_du = f.read()
2019-12-16 13:52:42 -08:00
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/du.out'), 'r', encoding='utf-8') as f:
2019-12-16 13:57:42 -08:00
self.osx_10_14_6_du = f.read()
2019-12-16 13:52:42 -08:00
# output
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/du.json'), 'r', encoding='utf-8') as f:
2019-12-16 13:52:42 -08:00
self.centos_7_7_du_json = json.loads(f.read())
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/du.json'), 'r', encoding='utf-8') as f:
2019-12-16 14:27:55 -08:00
self.ubuntu_18_4_du_json = json.loads(f.read())
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/du.json'), 'r', encoding='utf-8') as f:
2019-12-16 14:27:55 -08:00
self.osx_10_11_6_du_json = json.loads(f.read())
2019-12-16 13:52:42 -08:00
2020-03-04 19:40:32 -08:00
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/du.json'), 'r', encoding='utf-8') as f:
2019-12-16 13:57:42 -08:00
self.osx_10_14_6_du_json = json.loads(f.read())
2020-06-10 17:32:39 -07:00
def test_du_nodata(self):
"""
Test 'du' with no data
"""
self.assertEqual(jc.parsers.du.parse('', quiet=True), [])
2019-12-16 13:52:42 -08:00
def test_du_centos_7_7(self):
"""
Test 'du' on Centos 7.7
"""
self.assertEqual(jc.parsers.du.parse(self.centos_7_7_du, quiet=True), self.centos_7_7_du_json)
2019-12-16 14:27:55 -08:00
def test_du_ubuntu_18_4(self):
"""
Test 'du' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.du.parse(self.ubuntu_18_4_du, quiet=True), self.ubuntu_18_4_du_json)
def test_du_osx_10_11_6(self):
"""
Test 'du' on OSX 10.11.6
"""
self.assertEqual(jc.parsers.du.parse(self.osx_10_11_6_du, quiet=True), self.osx_10_11_6_du_json)
2019-12-16 13:52:42 -08:00
2019-12-16 13:57:42 -08:00
def test_du_osx_10_14_6(self):
"""
Test 'du' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.du.parse(self.osx_10_14_6_du, quiet=True), self.osx_10_14_6_du_json)
2019-12-16 13:52:42 -08:00
if __name__ == '__main__':
unittest.main()