File: details_txt.py

package info (click to toggle)
python-mbed-ls 1.6.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 496 kB
  • sloc: python: 2,785; makefile: 32; sh: 14
file content (112 lines) | stat: -rw-r--r-- 3,416 bytes parent folder | download | duplicates (3)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
"""
mbed SDK
Copyright (c) 2011-2015 ARM Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import unittest
import os
import errno
import logging

from mbed_lstools.main import create



class ParseMbedHTMTestCase(unittest.TestCase):
    """ Unit tests checking HTML parsing code for 'mbed.htm' files
    """

    details_txt_0226 = """Version: 0226
Build:   Aug 24 2015 17:06:30
Git Commit SHA: 27a236b9fe39c674a703c5c89655fbd26b8e27e1
Git Local mods: Yes
"""

    details_txt_0240 = """# DAPLink Firmware - see https://mbed.com/daplink
Unique ID: 0240000029164e45002f0012706e0006f301000097969900
HIF ID: 97969900
Auto Reset: 0
Automation allowed: 0
Daplink Mode: Interface
Interface Version: 0240
Git SHA: c765cbb590f57598756683254ca38b211693ae5e
Local Mods: 0
USB Interfaces: MSD, CDC, HID
Interface CRC: 0x26764ebf
"""

    def setUp(self):
        self.mbeds = create()

    def tearDown(self):
        pass

    def test_simplified_daplink_txt_content(self):
        # Fetch lines from DETAILS.TXT
        lines = self.details_txt_0226.splitlines()
        self.assertEqual(4, len(lines))

        # Check parsing content
        result = self.mbeds._parse_details(lines)
        self.assertEqual(4, len(result))
        self.assertIn('Version', result)
        self.assertIn('Build', result)
        self.assertIn('Git Commit SHA', result)
        self.assertIn('Git Local mods', result)

        # Check for daplink_version
        self.assertEqual(result['Version'], "0226")

    def test_extended_daplink_txt_content(self):
        # Fetch lines from DETAILS.TXT
        lines = self.details_txt_0240.splitlines()
        self.assertEqual(11, len(lines))

        # Check parsing content
        result = self.mbeds._parse_details(lines)
        self.assertEqual(11, len(result))   # 12th would be comment
        self.assertIn('Unique ID', result)
        self.assertIn('HIF ID', result)
        self.assertIn('Auto Reset', result)
        self.assertIn('Automation allowed', result)
        self.assertIn('Daplink Mode', result)
        self.assertIn('Interface Version', result)
        self.assertIn('Git SHA', result)
        self.assertIn('Local Mods', result)
        self.assertIn('USB Interfaces', result)
        self.assertIn('Interface CRC', result)

        # Check if we parsed comment line:
        # "# DAPLink Firmware - see https://mbed.com/daplink"
        for key in result:
            # Check if we parsed comment
            self.assertFalse(key.startswith('#'))
            # Check if we parsed
            self.assertFalse('https://mbed.com/daplink' in result[key])

        # Check for daplink_version
        # DAPlink <240 compatibility
        self.assertEqual(result['Interface Version'], "0240")
        self.assertEqual(result['Version'], "0240")

    def test_(self):
        pass

    def test_(self):
        pass

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