From 6901e4a23aad0b58cbbfac86c61917115d115dfe Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 22 Mar 2021 21:49:26 -0700 Subject: [PATCH] try setting timezone env variable before tests to ensure it is the same on all test systems --- runtests.sh | 6 +++--- tests/test_date.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ tests/test_last2.py | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 tests/test_date.py create mode 100644 tests/test_last2.py diff --git a/runtests.sh b/runtests.sh index 3518fd2e..e57e1414 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,10 +1,10 @@ #!/bin/bash -python3 -m unittest -v +TZ="America/Los_Angeles" python3 -m unittest -v echo echo "Running local-only tests:" echo -python3 -m unittest tests.localtest_last -v -python3 -m unittest tests.localtest_date -v +# python3 -m unittest tests.localtest_date -v +# python3 -m unittest tests.localtest_last -v diff --git a/tests/test_date.py b/tests/test_date.py new file mode 100644 index 00000000..c13fcc9e --- /dev/null +++ b/tests/test_date.py @@ -0,0 +1,46 @@ +import os +import json +import unittest +import jc.parsers.date + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/date.out'), 'r', encoding='utf-8') as f: + self.generic_date = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/date.out'), 'r', encoding='utf-8') as f: + self.ubuntu_20_04_date = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/date.json'), 'r', encoding='utf-8') as f: + self.generic_date_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/date.json'), 'r', encoding='utf-8') as f: + self.ubuntu_20_04_date_json = json.loads(f.read()) + + def test_date_nodata(self): + """ + Test 'date' with no data + """ + self.assertEqual(jc.parsers.date.parse('', quiet=True), {}) + + def test_date(self): + """ + Test 'date' + """ + self.assertEqual(jc.parsers.date.parse(self.generic_date, quiet=True), self.generic_date_json) + + def test_date_ubuntu_20_04(self): + """ + Test 'date' on Ubuntu 20.4 + """ + self.assertEqual(jc.parsers.date.parse(self.ubuntu_20_04_date, quiet=True), self.ubuntu_20_04_date_json) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_last2.py b/tests/test_last2.py new file mode 100644 index 00000000..32e70c5e --- /dev/null +++ b/tests/test_last2.py @@ -0,0 +1,40 @@ +import os +import json +import unittest +import jc.parsers.last + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/last-F.out'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_last_F = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/last-wF.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_last_wF = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/last-F.json'), 'r', encoding='utf-8') as f: + self.ubuntu_20_4_last_F_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/last-wF.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_last_wF_json = json.loads(f.read()) + + def test_last_F_ubuntu_20_4(self): + """ + Test 'last -F' on Ubuntu 20.4 + """ + self.assertEqual(jc.parsers.last.parse(self.ubuntu_20_4_last_F, quiet=True), self.ubuntu_20_4_last_F_json) + + def test_last_wF_centos_7_7(self): + """ + Test 'last -wF' on Centos 7.7 + """ + self.assertEqual(jc.parsers.last.parse(self.centos_7_7_last_wF, quiet=True), self.centos_7_7_last_wF_json) + + +if __name__ == '__main__': + unittest.main()