|
| 1 | +""" |
| 2 | +mbed SDK |
| 3 | +Copyright (c) 2016 ARM Limited |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +""" |
| 17 | + |
| 18 | +import unittest |
| 19 | +from collections import namedtuple |
| 20 | +from mock import patch, MagicMock |
| 21 | +from tools.detect_targets import get_interface_version |
| 22 | +from tools.test_api import get_autodetected_MUTS_list |
| 23 | + |
| 24 | +""" |
| 25 | +Tests for detect_targets.py |
| 26 | +""" |
| 27 | + |
| 28 | +class DetectTargetsTests(unittest.TestCase): |
| 29 | + """ |
| 30 | + Test cases for Detect Target functionality |
| 31 | + """ |
| 32 | + |
| 33 | + def setUp(self): |
| 34 | + """ |
| 35 | + Called before each test case |
| 36 | +
|
| 37 | + :return: |
| 38 | + """ |
| 39 | + # Gather a valid mount point from the host machine |
| 40 | + muts = get_autodetected_MUTS_list() |
| 41 | + |
| 42 | + count = 0 |
| 43 | + |
| 44 | + for mut in muts.values(): |
| 45 | + |
| 46 | + count += 1 |
| 47 | + self.valid_mount_point = mut['disk'] |
| 48 | + break |
| 49 | + |
| 50 | + # If no targets are found, there is no way to determine Host OS mount point. |
| 51 | + # Function should handle failure gracefully regardless of a mount point being present. |
| 52 | + # Therefore it is safe to assume a valid mount point. |
| 53 | + if count is 0: |
| 54 | + self.valid_mount_point = "D:" |
| 55 | + |
| 56 | + self.invalid_mount_point = "23z/e\n" |
| 57 | + self.missing_mount_point = None |
| 58 | + |
| 59 | + def tearDown(self): |
| 60 | + """ |
| 61 | + Nothing to tear down. |
| 62 | + Called after each test case |
| 63 | +
|
| 64 | + :return: |
| 65 | + """ |
| 66 | + pass |
| 67 | + |
| 68 | + def test_interface_version_valid_mount_point(self): |
| 69 | + |
| 70 | + interface_version = get_interface_version(self.valid_mount_point) |
| 71 | + assert len(interface_version) > 0 |
| 72 | + |
| 73 | + def test_interface_version_invalid_mount_point(self): |
| 74 | + |
| 75 | + interface_version = get_interface_version(self.invalid_mount_point) |
| 76 | + assert interface_version == 'unknown' |
| 77 | + |
| 78 | + def test_interface_version_missing_mount_point(self): |
| 79 | + |
| 80 | + interface_version = get_interface_version(self.missing_mount_point) |
| 81 | + assert interface_version == 'unknown' |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == '__main__': |
| 85 | + unittest.main() |
0 commit comments