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 0000000000000000000000000000000000000000..b711c37da04c44b3d2823bedbe3a5524445b61b0 --- /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 eb8b1f530f4bb931f119aaaa9d99191d749c84e7..a2a4f49a2fe3858851a0581778e26e6d49c85763 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