From 99c81b76a6f1ebf7fd94ac6b3d626cd301a1f9ee Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Sat, 2 May 2020 20:20:35 +0200 Subject: [PATCH] Basic jnius_config unit testing This is a first try at unit testing this module (before refactoring it). Follow up pull request will make a complete coverage. --- tests/test_jnius_config.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_jnius_config.py diff --git a/tests/test_jnius_config.py b/tests/test_jnius_config.py new file mode 100644 index 0000000..8b06d4f --- /dev/null +++ b/tests/test_jnius_config.py @@ -0,0 +1,35 @@ +import sys +import pytest +import jnius_config + + +class TestJniusConfig: + def setup_method(self): + """Resets the options global.""" + jnius_config.options = [] + jnius_config.vm_running = False + + def teardown_method(self): + self.setup_method() + + def test_set_options(self): + assert jnius_config.vm_running is False + assert jnius_config.options == [] + jnius_config.set_options("option1", "option2") + assert jnius_config.options == ["option1", "option2"] + jnius_config.set_options("option3") + assert jnius_config.options == ["option3"] + + def test_set_options_vm_running(self): + assert jnius_config.vm_running is False + jnius_config.set_options("option1", "option2") + jnius_config.vm_running = True + with pytest.raises(ValueError) as ex_info: + jnius_config.set_options("option1", "option2") + pytest.mark.skipif( + sys.version_info < (3, 5), reason="Exception args are different on Python 2" + ) + assert ( + "VM is already running, can't set options; VM started at" + in ex_info.value.args[0] + )