Code review comment for lp:~adeuring/launchpad/bug-457475-udev-device-id

Revision history for this message
Abel Deuring (adeuring) wrote :

Sorry, forgot to write a test for UdevDevice.id. Now added.

The diff of the complete changes is now:

=== modified file 'lib/canonical/launchpad/scripts/hwdbsubmissions.py'
--- lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-10-21 10:06:31 +0000
+++ lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-10-21 16:43:31 +0000
@@ -503,6 +503,7 @@
         devices = []
         device = None
         line_number = 0
+ device_id = 0

         for line_number, line in enumerate(udev_data):
             if len(line) == 0:
@@ -518,9 +519,11 @@

             key, value = record
             if device is None:
+ device_id += 1
                 device = {
                     'E': {},
                     'S': [],
+ 'id': device_id,
                     }
                 devices.append(device)
             # Some attribute lines have a space character after the
@@ -2776,6 +2779,11 @@
             return None
         return controller

+ @property
+ def id(self):
+ return self.udev['id']
+
+
 class ProcessingLoop(object):
     """An `ITunableLoop` for processing HWDB submissions."""

=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py'
--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-10-12 14:50:22 +0000
+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-10-21 16:47:04 +0000
@@ -635,6 +635,7 @@
                         'MODALIAS': 'acpi:LNXSYSTM:',
                         },
                     'S': [],
+ 'id': 1,
                     },
                 {
                     'P': '/devices/pci0000:00/0000:00:1a.0',
@@ -643,6 +644,7 @@
                         'DEVPATH': '/devices/pci0000:00/0000:00:1a.0',
                         },
                     'S': ['char/189:256'],
+ 'id': 2,
                     },
                 ],
             result,
@@ -704,6 +706,7 @@
                     'E': {},
                     'S': [],
                     'W': '2',
+ 'id': 1,
                     },
                 ],
             result,

=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py'
--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-10-21 10:06:31 +0000
+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-10-22 09:00:19 +0000
@@ -3036,7 +3036,8 @@
                 'DEVPATH': '/devices/LNXSYSTM:00',
                 'MODALIAS': 'acpi:LNXSYSTM:',
                 'SUBSYSTEM': 'acpi',
- }
+ },
+ 'id': 1,
             }

         self.root_device_dmi_data = {
@@ -4185,6 +4186,11 @@
             'provide bus, vendor ID, product ID or product name: None None '
             'None None /devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0')

+ def test_device_id(self):
+ """Each UdevDevice has a property 'id'."""
+ device = UdevDevice(None, self.root_device)
+ self.assertEqual(1, device.id)
+

 class TestHWDBSubmissionTablePopulation(TestCaseHWDB):
     """Tests of the HWDB popoluation with submitted data."""

« Back to merge proposal