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
diff --git a/checkbox_support/parsers/tests/test_sysfs_usb.py b/checkbox_support/parsers/tests/test_sysfs_usb.py
index a47f0a7..bc3e14d 100644
--- a/checkbox_support/parsers/tests/test_sysfs_usb.py
+++ b/checkbox_support/parsers/tests/test_sysfs_usb.py
@@ -18,6 +18,8 @@
1818
1919
20"""Tests for the sysfs_usb module."""20"""Tests for the sysfs_usb module."""
21import os
22import tempfile
21import textwrap23import textwrap
2224
23from unittest import TestCase25from unittest import TestCase
@@ -58,12 +60,20 @@ class TestIsHex(TestCase):
5860
5961
60class TestUsbIds(TestCase):62class TestUsbIds(TestCase):
63 @classmethod
64 def setUpClass(cls):
65 cls._test_usb_ids = tempfile.NamedTemporaryFile(delete=False)
66
67 @classmethod
68 def tearDownClass(cls):
69 os.remove(cls._test_usb_ids.name)
70
61 """Test for the UsbIds class."""71 """Test for the UsbIds class."""
62 def test_empty(self):72 def test_empty(self):
63 """Test empty database."""73 """Test empty database."""
64 mopen = mock_open(read_data='')74 mopen = mock_open(read_data='')
65 with patch('builtins.open', mopen):75 with patch('builtins.open', mopen):
66 ids = UsbIds()76 ids = UsbIds(self._test_usb_ids.name)
67 with self.assertRaises(KeyError):77 with self.assertRaises(KeyError):
68 ids.decode_product(42, 42)78 ids.decode_product(42, 42)
69 self.assertEqual(ids.decode_protocol(42, 42, 42), '')79 self.assertEqual(ids.decode_protocol(42, 42, 42), '')
@@ -76,7 +86,7 @@ class TestUsbIds(TestCase):
76 """)86 """)
77 mopen = mock_open(read_data=usb_ids_content)87 mopen = mock_open(read_data=usb_ids_content)
78 with patch('builtins.open', mopen):88 with patch('builtins.open', mopen):
79 ids = UsbIds()89 ids = UsbIds(self._test_usb_ids.name)
80 self.assertEqual(ids.decode_product(0x42, 0x42), 'ACME Seafourium')90 self.assertEqual(ids.decode_product(0x42, 0x42), 'ACME Seafourium')
8191
82 def test_vendor_only(self):92 def test_vendor_only(self):
@@ -86,7 +96,7 @@ class TestUsbIds(TestCase):
86 """)96 """)
87 mopen = mock_open(read_data=usb_ids_content)97 mopen = mock_open(read_data=usb_ids_content)
88 with patch('builtins.open', mopen):98 with patch('builtins.open', mopen):
89 ids = UsbIds()99 ids = UsbIds(self._test_usb_ids.name)
90 self.assertEqual(ids.decode_vendor(0x42), 'ACME')100 self.assertEqual(ids.decode_vendor(0x42), 'ACME')
91101
92 def test_full_protocol(self):102 def test_full_protocol(self):
@@ -98,7 +108,7 @@ class TestUsbIds(TestCase):
98 """)108 """)
99 mopen = mock_open(read_data=usb_ids_content)109 mopen = mock_open(read_data=usb_ids_content)
100 with patch('builtins.open', mopen):110 with patch('builtins.open', mopen):
101 ids = UsbIds()111 ids = UsbIds(self._test_usb_ids.name)
102 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),112 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),
103 'Explosives:Bomb:Boom')113 'Explosives:Bomb:Boom')
104114
@@ -110,7 +120,7 @@ class TestUsbIds(TestCase):
110 """)120 """)
111 mopen = mock_open(read_data=usb_ids_content)121 mopen = mock_open(read_data=usb_ids_content)
112 with patch('builtins.open', mopen):122 with patch('builtins.open', mopen):
113 ids = UsbIds()123 ids = UsbIds(self._test_usb_ids.name)
114 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),124 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),
115 'Explosives:Bomb')125 'Explosives:Bomb')
116126
@@ -121,6 +131,6 @@ class TestUsbIds(TestCase):
121 """)131 """)
122 mopen = mock_open(read_data=usb_ids_content)132 mopen = mock_open(read_data=usb_ids_content)
123 with patch('builtins.open', mopen):133 with patch('builtins.open', mopen):
124 ids = UsbIds()134 ids = UsbIds(self._test_usb_ids.name)
125 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),135 self.assertEqual(ids.decode_protocol(0x42, 0x06, 0x01),
126 'Explosives')136 'Explosives')

Subscribers

People subscribed via source and target branches