aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--test.py78
2 files changed, 79 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 97aa15b..8cfc47e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
/ssh_negotiate_term
+/__pycache__
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..7a784be
--- /dev/null
+++ b/test.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python3
+import configparser
+import unittest
+
+from ssh_negotiate_term import SSHNegotiateTerm
+
+class TestSSHNegotiateTerm(unittest.TestCase):
+
+ def setUp(self):
+ config = configparser.ConfigParser()
+ config['patterns'] = SSHNegotiateTerm.DEFAULT_PATTERNS
+ config['ssh'] = {}
+ config['ssh']['path'] = SSHNegotiateTerm.DEFAULT_SSH
+ config['translations'] = SSHNegotiateTerm.DEFAULT_TRANSLATIONS
+ self.snt_config = config
+
+ def test_instantiate(self):
+ snt = SSHNegotiateTerm('foo', [], self.snt_config)
+ self.assertIsInstance(snt, SSHNegotiateTerm)
+
+ def test_hostname(self):
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', 'examplehost'], self.snt_config)
+ self.assertEqual(snt.term, 'screen-256color')
+
+ def test_fqdn(self):
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', 'host.example.net.'], self.snt_config)
+ self.assertEqual(snt.term, 'screen-256color')
+
+ def test_ipv4(self):
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', '192.0.2.1'], self.snt_config)
+ self.assertEqual(snt.term, 'screen')
+
+ def test_ipv6(self):
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', '2001:0db8::1'], self.snt_config)
+ self.assertEqual(snt.term, 'screen')
+
+ def test_complex_command_line(self):
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', '-4', '-NfoSetEnv=FOO=BAR', '-NtT', '--', '192.0.2.1', 'runcmd'], self.snt_config)
+ self.assertEqual(snt.term, 'screen')
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', '-4', '-NfoSetEnv=FOO=BAR', '-NtT', '--', 'examplehost', 'runcmd'], self.snt_config)
+ self.assertEqual(snt.term, 'screen-256color')
+
+ def test_null_term(self):
+ snt = SSHNegotiateTerm(None, ['ssh', '192.0.2.1'], self.snt_config)
+ self.assertEqual(snt.term, None)
+
+ def test_unknown_term(self):
+ snt = SSHNegotiateTerm('qwyjibo', ['ssh', '192.0.2.1'], self.snt_config)
+ self.assertEqual(snt.term, 'qwyjibo')
+
+ def test_untranslated_term(self):
+ snt = SSHNegotiateTerm('screen', ['ssh', '192.0.2.1'], self.snt_config)
+ self.assertEqual(snt.term, 'screen')
+
+ def test_patterns_simple(self):
+ config = self.snt_config
+ self.snt_config['patterns']['examplehost'] = '^examplehost$'
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', 'examplehost'], self.snt_config)
+ self.assertEqual(snt.term, 'screen')
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', 'examplehost2'], self.snt_config)
+ self.assertEqual(snt.term, 'screen-256color')
+
+ def test_pattern_complex(self):
+ config = self.snt_config
+ self.snt_config['patterns']['complexhost'] = '^[a-z]{3}-[a-z]{2,}-[a-z]{2,}-[0-9]'
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', 'abc-example-ar-1'], self.snt_config)
+ self.assertEqual(snt.term, 'screen')
+ snt = SSHNegotiateTerm('screen-256color', ['ssh', 'abc-example-ar-a1'], self.snt_config)
+ self.assertEqual(snt.term, 'screen-256color')
+
+ def test_translations(self):
+ for outer in self.snt_config['translations']:
+ snt = SSHNegotiateTerm(outer, ['ssh', '192.0.2.1'], self.snt_config)
+ inner = self.snt_config['translations'][outer]
+ self.assertEqual(snt.term, inner)
+
+if __name__ == '__main__':
+ unittest.main()