From e14647f553bef558f672dd04197938eb8b8fb368 Mon Sep 17 00:00:00 2001
From: thijs snijder <snijder@astron.nl>
Date: Tue, 12 Apr 2022 12:42:19 +0200
Subject: [PATCH] added test

---
 .../test/toolkit/test_mib_compiler.py         | 29 +++++++++++++++++++
 .../toolkit/mib_compiler/mib_compiler.py      |  6 ++--
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 tangostationcontrol/tangostationcontrol/test/toolkit/test_mib_compiler.py

diff --git a/tangostationcontrol/tangostationcontrol/test/toolkit/test_mib_compiler.py b/tangostationcontrol/tangostationcontrol/test/toolkit/test_mib_compiler.py
new file mode 100644
index 000000000..b711c37da
--- /dev/null
+++ b/tangostationcontrol/tangostationcontrol/test/toolkit/test_mib_compiler.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the LOFAR 2.0 Station Software
+#
+#
+#
+# Distributed under the terms of the APACHE license.
+# See LICENSE.txt for more info.
+
+from tangostationcontrol.test import base
+import tangostationcontrol.toolkit.mib_compiler as mib_compiler
+import sys
+from os.path import isfile
+from tempfile import TemporaryDirectory
+from unittest import mock
+
+class TestCompiler(base.TestCase):
+    def test_compile(self):
+        with TemporaryDirectory() as tmpdir:
+            new_sys_argv = [sys.argv[0], "--mibs", "TEST-MIB",
+                            "--source", "/opt/lofar/tango/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mibs",
+                            "http://www.net-snmp.org/docs/mibs/",
+                            "--destination", f"{tmpdir}"]
+            with mock.patch.object(mib_compiler.sys, 'argv', new_sys_argv):
+                with self.assertRaises(SystemExit):
+                    mib_compiler.main()
+
+            # check if file was written
+            self.assertTrue(isfile(f"{tmpdir}/TEST-MIB.py"))
\ No newline at end of file
diff --git a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py
index eb8b1f530..a2a4f49a2 100644
--- a/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py
+++ b/tangostationcontrol/tangostationcontrol/toolkit/mib_compiler/mib_compiler.py
@@ -27,8 +27,7 @@ def mib_compile(mib_list : list, src, dst):
             raise Exception(f"Something went wrong, try checking whether all the mib fills imported by the provided mib files are present (To do this enable debug options and scroll up) ") from e
 
 
-
-if __name__ == "__main__":
+def main():
     abs_path = str(Path().absolute()).replace("\\", "/")
     out_path = f"{abs_path}/output_pymibs"
     in_path = f"{abs_path}/mibs"
@@ -62,3 +61,6 @@ if __name__ == "__main__":
 
     mib_compile(mib_list=mibs, src=source, dst=destination)
 
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file
-- 
GitLab