File: test_ssh_conf.py

package info (click to toggle)
jc 1.25.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,104 kB
  • sloc: python: 70,400; sh: 724; xml: 278; makefile: 5
file content (95 lines) | stat: -rw-r--r-- 2,565 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import unittest
import json
from typing import Dict
from jc.parsers.ssh_conf import parse

THIS_DIR = os.path.dirname(os.path.abspath(__file__))


class MyTests(unittest.TestCase):
    f_in: Dict = {}
    f_json: Dict = {}

    @classmethod
    def setUpClass(cls):
        fixtures = {
            'ssh_config1': (
                'fixtures/generic/ssh_config1',
                'fixtures/generic/ssh_config1.json'),
            'ssh_config2': (
                'fixtures/generic/ssh_config2',
                'fixtures/generic/ssh_config2.json'),
            'ssh_config3': (
                'fixtures/generic/ssh_config3',
                'fixtures/generic/ssh_config3.json'),
            'ssh_config4': (
                'fixtures/generic/ssh_config4',
                'fixtures/generic/ssh_config4.json'),
            'ssh_config5': (
                'fixtures/generic/ssh_config5',
                'fixtures/generic/ssh_config5.json')
        }

        for file, filepaths in fixtures.items():
            with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
                 open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
                cls.f_in[file] = a.read()
                cls.f_json[file] = json.loads(b.read())


    def test_ssh_nodata(self):
        """
        Test 'ssh' with no data
        """
        self.assertEqual(parse('', quiet=True), [])


    def test_ssh_config1(self):
        """
        Test 'ssh' config 1
        """
        self.assertEqual(
            parse(self.f_in['ssh_config1'], quiet=True),
            self.f_json['ssh_config1']
        )

    def test_ssh_config2(self):
        """
        Test 'ssh' config 2
        """
        self.assertEqual(
            parse(self.f_in['ssh_config2'], quiet=True),
            self.f_json['ssh_config2']
        )

    def test_ssh_config3(self):
        """
        Test 'ssh' config 3
        """
        self.assertEqual(
            parse(self.f_in['ssh_config3'], quiet=True),
            self.f_json['ssh_config3']
        )

    def test_ssh_config4(self):
        """
        Test 'ssh' config 4
        """
        self.assertEqual(
            parse(self.f_in['ssh_config4'], quiet=True),
            self.f_json['ssh_config4']
        )

    def test_ssh_config5(self):
        """
        Test 'ssh' config 5
        """
        self.assertEqual(
            parse(self.f_in['ssh_config5'], quiet=True),
            self.f_json['ssh_config5']
        )


if __name__ == '__main__':
    unittest.main()