Merge ~sylvain-pineau/checkbox-support:fake_usb.ids_unittest into checkbox-support:master

Proposed by Sylvain Pineau
Status: Rejected
Rejected by: Sylvain Pineau
Proposed branch: ~sylvain-pineau/checkbox-support:fake_usb.ids_unittest
Merge into: checkbox-support:master
Diff against target: 79 lines (+16/-6)
1 file modified
checkbox_support/parsers/tests/test_sysfs_usb.py (+16/-6)
Reviewer Review Type Date Requested Status
Checkbox Developers Pending
Review via email: mp+392296@code.launchpad.net

Description of the change

a simple fix to run the unit tests using a tempfile instead of real usb.ids

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

The temporary file is not needed. What was missing, was the patch for isfile calls. See here:
https://code.launchpad.net/~kissiel/checkbox-support/+git/checkbox-support/+merge/392299

Unmerged commits

fedb50d... by Sylvain Pineau

parsers:tests:sysfs_usb: Use a amedTemporaryFile to fake usb.ids

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/parsers/tests/test_sysfs_usb.py b/checkbox_support/parsers/tests/test_sysfs_usb.py
2index a47f0a7..bc3e14d 100644
3--- a/checkbox_support/parsers/tests/test_sysfs_usb.py
4+++ b/checkbox_support/parsers/tests/test_sysfs_usb.py
5@@ -18,6 +18,8 @@
6
7
8 """Tests for the sysfs_usb module."""
9+import os
10+import tempfile
11 import textwrap
12
13 from unittest import TestCase
14@@ -58,12 +60,20 @@ class TestIsHex(TestCase):
15
16
17 class TestUsbIds(TestCase):
18+ @classmethod
19+ def setUpClass(cls):
20+ cls._test_usb_ids = tempfile.NamedTemporaryFile(delete=False)
21+
22+ @classmethod
23+ def tearDownClass(cls):
24+ os.remove(cls._test_usb_ids.name)
25+
26 """Test for the UsbIds class."""
27 def test_empty(self):
28 """Test empty database."""
29 mopen = mock_open(read_data='')
30 with patch('builtins.open', mopen):
31- ids = UsbIds()
32+ ids = UsbIds(self._test_usb_ids.name)
33 with self.assertRaises(KeyError):
34 ids.decode_product(42, 42)
35 self.assertEqual(ids.decode_protocol(42, 42, 42), '')
36@@ -76,7 +86,7 @@ class TestUsbIds(TestCase):
37 """)
38 mopen = mock_open(read_data=usb_ids_content)
39 with patch('builtins.open', mopen):
40- ids = UsbIds()
41+ ids = UsbIds(self._test_usb_ids.name)
42 self.assertEqual(ids.decode_product(0x42, 0x42), 'ACME Seafourium')
43
44 def test_vendor_only(self):
45@@ -86,7 +96,7 @@ class TestUsbIds(TestCase):
46 """)
47 mopen = mock_open(read_data=usb_ids_content)
48 with patch('builtins.open', mopen):
49- ids = UsbIds()
50+ ids = UsbIds(self._test_usb_ids.name)
51 self.assertEqual(ids.decode_vendor(0x42), 'ACME')
52
53 def test_full_protocol(self):
54@@ -98,7 +108,7 @@ class TestUsbIds(TestCase):
55 """)
56 mopen = mock_open(read_data=usb_ids_content)
57 with patch('builtins.open', mopen):
58- ids = UsbIds()
59+ ids = UsbIds(self._test_usb_ids.name)
60 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),
61 'Explosives:Bomb:Boom')
62
63@@ -110,7 +120,7 @@ class TestUsbIds(TestCase):
64 """)
65 mopen = mock_open(read_data=usb_ids_content)
66 with patch('builtins.open', mopen):
67- ids = UsbIds()
68+ ids = UsbIds(self._test_usb_ids.name)
69 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),
70 'Explosives:Bomb')
71
72@@ -121,6 +131,6 @@ class TestUsbIds(TestCase):
73 """)
74 mopen = mock_open(read_data=usb_ids_content)
75 with patch('builtins.open', mopen):
76- ids = UsbIds()
77+ ids = UsbIds(self._test_usb_ids.name)
78 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),
79 'Explosives')

Subscribers

People subscribed via source and target branches