From 6bf7d318c6627069c428d8ce974211c9c5476168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Otto?= Date: Sun, 25 Aug 2024 19:14:06 +0200 Subject: [PATCH] Add tests for file cli --- test/test_cli.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/test_cli.py diff --git a/test/test_cli.py b/test/test_cli.py new file mode 100644 index 0000000..f028857 --- /dev/null +++ b/test/test_cli.py @@ -0,0 +1,33 @@ +from unittest import TestCase +import subprocess +import os + +script_dir = os.path.dirname(os.path.realpath(__file__)) + + +class CheckFileCli(TestCase): + + json_file = os.path.join(script_dir, 'fixtures', 'aasx', 'valid', 'json', 'aasx', 'the_aas.json') + xml_file = os.path.join(script_dir, 'fixtures', 'aasx', 'valid', 'xml', 'aasx', 'the_aas.xml') + + def invoke(self, args: list): + result = subprocess.check_output(["python", "-m", "aas_test_engines", "check_file"] + args) + return result.decode() + + def test_no_arguments(self): + with self.assertRaises(subprocess.CalledProcessError): + self.invoke([]) + + def test_json(self): + self.invoke([self.json_file, '--format', 'json']) + + def test_xml(self): + self.invoke([self.xml_file, '--format', 'xml']) + + def test_html_output(self): + result = self.invoke([self.json_file, '--format', 'json', '--output', 'html']) + self.assertTrue(result.startswith('')) + + def test_invalid_file(self): + with self.assertRaises(subprocess.CalledProcessError): + self.invoke([self.json_file, '--format', 'xml'])