diff --git a/tests/fixtures/ubuntu-18.04/crontab-u.json b/tests/fixtures/ubuntu-18.04/crontab-u.json new file mode 100644 index 00000000..34dc4021 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/crontab-u.json @@ -0,0 +1 @@ +{"variables": [{"name": "PATH", "value": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"}, {"name": "SHELL", "value": "/bin/sh"}], "schedule": [{"minute": ["25"], "hour": ["6"], "day_of_month": ["*"], "month": ["*"], "day_of_week": ["*"], "user": "root", "command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )"}, {"minute": ["47"], "hour": ["6"], "day_of_month": ["*"], "month": ["*"], "day_of_week": ["7"], "user": "root", "command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )"}, {"minute": ["52"], "hour": ["6"], "day_of_month": ["1"], "month": ["*"], "day_of_week": ["*"], "user": "root", "command": "test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )"}]} diff --git a/tests/fixtures/ubuntu-18.04/crontab.out b/tests/fixtures/ubuntu-18.04/crontab-u.out similarity index 100% rename from tests/fixtures/ubuntu-18.04/crontab.out rename to tests/fixtures/ubuntu-18.04/crontab-u.out diff --git a/tests/fixtures/ubuntu-18.04/crontab.json b/tests/fixtures/ubuntu-18.04/crontab.json deleted file mode 100644 index 1f2b5740..00000000 --- a/tests/fixtures/ubuntu-18.04/crontab.json +++ /dev/null @@ -1 +0,0 @@ -{"variables": [{"name": "PATH", "value": "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"}, {"name": "SHELL", "value": "/bin/sh"}], "schedule": [{"minute": ["25"], "hour": ["6"], "day_of_month": ["*"], "month": ["*"], "day_of_week": ["*"], "command": "root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )"}, {"minute": ["47"], "hour": ["6"], "day_of_month": ["*"], "month": ["*"], "day_of_week": ["7"], "command": "root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )"}, {"minute": ["52"], "hour": ["6"], "day_of_month": ["1"], "month": ["*"], "day_of_week": ["*"], "command": "root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )"}]} diff --git a/tests/test_crontab.py b/tests/test_crontab.py index 3abc8952..9f9558bc 100644 --- a/tests/test_crontab.py +++ b/tests/test_crontab.py @@ -13,28 +13,16 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.out'), 'r') as f: self.centos_7_7_crontab = f.read() - with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/crontab.out'), 'r') as f: - self.ubuntu_18_4_crontab = f.read() - # output with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/crontab.json'), 'r') as f: self.centos_7_7_crontab_json = json.loads(f.read()) - with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/crontab.json'), 'r') as f: - self.ubuntu_18_4_crontab_json = json.loads(f.read()) - def test_crontab_centos_7_7(self): """ Test 'crontab' on Centos 7.7 """ self.assertEqual(jc.parsers.crontab.parse(self.centos_7_7_crontab, quiet=True), self.centos_7_7_crontab_json) - def test_crontab_ubuntu_18_4(self): - """ - Test 'crontab' on Ubuntu 18.4 - """ - self.assertEqual(jc.parsers.crontab.parse(self.ubuntu_18_4_crontab, quiet=True), self.ubuntu_18_4_crontab_json) - if __name__ == '__main__': unittest.main() diff --git a/tests/test_crontab_u.py b/tests/test_crontab_u.py new file mode 100644 index 00000000..08826f4c --- /dev/null +++ b/tests/test_crontab_u.py @@ -0,0 +1,28 @@ +import os +import json +import unittest +import jc.parsers.crontab_u + +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-18.04/crontab-u.out'), 'r') as f: + self.ubuntu_18_4_crontab_u = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/crontab-u.json'), 'r') as f: + self.ubuntu_18_4_crontab_u_json = json.loads(f.read()) + + def test_crontab_u_ubuntu_18_4(self): + """ + Test 'crontab' on Ubuntu 18.4 (has a user field) + """ + self.assertEqual(jc.parsers.crontab_u.parse(self.ubuntu_18_4_crontab_u, quiet=True), self.ubuntu_18_4_crontab_u_json) + + +if __name__ == '__main__': + unittest.main()