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