def test_01_instance_raise_exception_1(self): with self.assertRaises(TypeError): nm = NMCLI(text="Not boolean")
def test_00_constructor_2(self): _env = {'LANG': 'C'} nm = NMCLI(env=_env) self.assertEqual(nm.env, _env)
def test_01_instance_raise_exception_0(self): with self.assertRaises(NameError): nm = NMCLI(path='/usr/local/not_nmcli')
If you want to pass environment variables when executing nmcli, you can specify 'env' argument. nm = NMCLI(env={'LANG': 'C'}) Throw TypeError exception if you specify other than 'None' or a dictionary. If you need super-user priviledge to execute 'nmcli' command, you can specify 'sudo' argument. nm = NMCLI(sudo='path/to/sudo') Throw NameError exception if path-to-sudo ending without 'sudo'. Throw FileNotFoundError if the file specified is not executable. """ nm = NMCLI(text=True, env={'LANG':'C'}) """ All methods return a tuple containing returncode, stdout and stderr. returncode : exit status code from 'nmcli' command stdout : standard outout from 'nmcli' command some methods return a dict or list stderr : standard error output from 'nmcli' empty str is returned when 'nmcli' finished successfully """ # show version of 'nmcli' returncode, stdout, stderr = nm.show_version() print(stdout)