Debian Codegraph @

test_PhysicalDevice.py

raw
1 #!/usr/bin/python3
2
3 ## Copyright (C) 2015 Red Hat, Inc.
4 ## Authors:
5 ## Tim Waugh <[email protected]>
6
7 ## This program is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
11
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
16
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program; if not, write to the Free Software
19 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 import pytest
22 try:
23 import cups
24 from PhysicalDevice import PhysicalDevice
25 from cupshelpers import cupshelpers
26 except ImportError:
27 cups = None
28
29 @pytest.mark.skipif(cups is None, reason="cups module not available")
30 def test_ordering():
31 # See https://bugzilla.redhat.com/show_bug.cgi?id=1154686
32 device = cupshelpers.Device("dnssd://Abc%20Def%20%5BABCDEF%5D._ipp._tcp.local/",
33 **{'device-class': "network",
34 'device-make-and-model': "Abc Def",
35 'device-id': "MFG:Abc;MDL:Def;"})
36 phys = PhysicalDevice (device)
37
38 device = cupshelpers.Device("hp:/net/Abc_Def?hostname=ABCDEF",
39 **{'device-class': "network",
40 'device-make-and-model': "Abc Def",
41 'device-id': "MFG:Abc;MDL:Def;"})
42 phys.add_device (device)
43 devices = phys.get_devices ()
44 assert devices[0].uri.startswith ("hp:")
45
46 device = cupshelpers.Device("usb://Abc/Def",
47 **{'device-class': "direct",
48 'device-make-and-model': "Abc Def",
49 'device-id': "MFG:Abc;MDL:Def;"})
50 phys = PhysicalDevice (device)
51 device = cupshelpers.Device("hp://Abc/Def",
52 **{'device-class': "direct",
53 'device-make-and-model': "Abc Def",
54 'device-id': "MFG:Abc;MDL:Def;"})
55 phys.add_device (device)
56 devices = phys.get_devices ()
57 assert devices[0].uri.startswith ("hp")
58
59 dev1 = cupshelpers.Device("hp:/usb/HP_Color_LaserJet_CP3525?serial=CNCTC8G0QX",
60 **{'device-id':'MFG:Hewlett-Packard;CMD:PJL,MLC,BIDI-ECP,PJL,PCLXL,PCL,POSTSCRIPT,PDF;MDL:HP Color LaserJet CP3525;CLS:PRINTER;DES:Hewlett-Packard Color LaserJet CP3525;',
61 'device-make-and-model':'HP Color LaserJet CP3525',
62 'device-class':'direct'})
63 phys = PhysicalDevice (dev1)
64 dev2 = cupshelpers.Device('usb://HP/Color%20LaserJet%20CP3525?serial=CNCTC8G0QX',
65 **{'device-id':'MFG:Hewlett-Packard;CMD:PJL,MLC,BIDI-ECP,PJL,PCLXL,PCL,POSTSCRIPT,PDF;MDL:HP Color LaserJet CP3525;CLS:PRINTER;DES:Hewlett-Packard Color LaserJet CP3525;',
66 'device-make-and-model':'HP Color LaserJet CP3525',
67 'device-class':'direct'})
68
69 # hp device should sort < usb device
70 assert dev1 < dev2
71
72 phys.add_device (dev2)
73 devices = phys.get_devices ()
74 assert devices[0] < devices[1]
75 assert devices[0].uri.startswith ("hp")