def test_append_hostlist(self): expected = textwrap.dedent('''\ Host myhost.com PreferredAuthentications publickey User myuser ForwardAgent no Host myhost.net myhost.org User bob Port 23 ''') config = textwrap.dedent('''\ Host myhost.com PreferredAuthentications publickey User myuser ForwardAgent no''') ssh_config = loads(config) ssh_config.append( HostBlock( HostList(["myhost.net", "myhost.org"]), KeywordSet([ ("User", "bob"), ("Port", "23"), ]), )) self.assertEqual(expected, dumps(ssh_config))
def test_load_and_dump(self): config = textwrap.dedent('''\ Host myhost.com PreferredAuthentications publickey User myuser ForwardAgent no Host myhost.net myhost.org User bob Port 23 ''') ssh_config = loads(config) self.assertEqual(config, dumps(ssh_config))
def test_dump_equals_dumps(self): config = textwrap.dedent('''\ Host myhost.com PreferredAuthentications publickey User myuser ForwardAgent no Host myhost.net myhost.org User bob Port 23 ''') ssh_config = loads(config) fd = StringIO() dump(ssh_config, fd) self.assertEqual(dumps(ssh_config), fd.getvalue())
def test_no_sep_lines(self): expected = textwrap.dedent('''\ Host * ConnectTimeout 30 Host myhost.com !insecure.com PreferredAuthentications publickey User alice ForwardAgent no Host myhost.net myhost.org User bob Port 23 Host * User nouser ForwardX11 no ''') config = self.__class__.Config ssh_config = loads(config) self.assertEqual(expected, dumps(ssh_config, sep_lines=0))
def test_indent_tabs(self): expected = textwrap.dedent('''\ Host * \tConnectTimeout 30 Host myhost.com !insecure.com \tPreferredAuthentications publickey \tUser alice \tForwardAgent no Host myhost.net myhost.org \tUser bob \tPort 23 Host * \tUser nouser \tForwardX11 no ''') config = self.__class__.Config ssh_config = loads(config) self.assertEqual(expected, dumps(ssh_config, indent='\t'))