Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
auke.klazema
HPIB
Commits
be7c998e
Commit
be7c998e
authored
Feb 16, 2018
by
auke.klazema
Browse files
Rename of PrologixGpiUsb Class
parent
28c322a9
Changes
3
Show whitespace changes
Inline
Side-by-side
hpib.py
View file @
be7c998e
...
@@ -4,7 +4,7 @@ import re
...
@@ -4,7 +4,7 @@ import re
import
platform
import
platform
class
P
ROLOGIX_GPIB_USB
():
class
P
rologixGpibUsb
():
def
__init__
(
self
,
port
=
""
,
timeout
=
1
,
portFormat
=
"%d"
,
maxDeviceNum
=
9
,
verbose
=
False
,
def
__init__
(
self
,
port
=
""
,
timeout
=
1
,
portFormat
=
"%d"
,
maxDeviceNum
=
9
,
verbose
=
False
,
findDevices
=
False
):
findDevices
=
False
):
if
port
==
""
:
if
port
==
""
:
...
...
startup.py
View file @
be7c998e
...
@@ -7,7 +7,7 @@ import time
...
@@ -7,7 +7,7 @@ import time
##import kapteyn
##import kapteyn
p
=
hpib
.
P
ROLOGIX_GPIB_USB
()
p
=
hpib
.
P
rologixGpibUsb
()
sml
=
hpib
.
hpib_device
(
28
,
p
)
sml
=
hpib
.
hpib_device
(
28
,
p
)
smx
=
hpib
.
hpib_device
(
14
,
p
)
smx
=
hpib
.
hpib_device
(
14
,
p
)
esmc
=
hpib
.
hpib_device
(
1
,
p
)
esmc
=
hpib
.
hpib_device
(
1
,
p
)
...
...
test/test_hpib.py
View file @
be7c998e
...
@@ -17,19 +17,19 @@ class PrologixGpibUsbTest(unittest.TestCase):
...
@@ -17,19 +17,19 @@ class PrologixGpibUsbTest(unittest.TestCase):
self
.
platform_mock
.
system
.
return_value
=
"Linux"
self
.
platform_mock
.
system
.
return_value
=
"Linux"
def
test_when_platform_linux_port_gets_set_to_ttyusb0
(
self
):
def
test_when_platform_linux_port_gets_set_to_ttyusb0
(
self
):
hpib
.
P
ROLOGIX_GPIB_USB
()
hpib
.
P
rologixGpibUsb
()
self
.
serial_mock
.
assert_called_with
(
'/dev/ttyUSB0'
,
timeout
=
1
)
self
.
serial_mock
.
assert_called_with
(
'/dev/ttyUSB0'
,
timeout
=
1
)
def
test_when_platform_darwin_port_gets_set_to_ttys000
(
self
):
def
test_when_platform_darwin_port_gets_set_to_ttys000
(
self
):
self
.
platform_mock
.
system
.
return_value
=
"Darwin"
self
.
platform_mock
.
system
.
return_value
=
"Darwin"
hpib
.
P
ROLOGIX_GPIB_USB
()
hpib
.
P
rologixGpibUsb
()
self
.
serial_mock
.
assert_called_with
(
'/dev/ttys000'
,
timeout
=
1
)
self
.
serial_mock
.
assert_called_with
(
'/dev/ttys000'
,
timeout
=
1
)
def
test_getDevices_returns_not_scanned_when_find_devices_is_false
(
self
):
def
test_getDevices_returns_not_scanned_when_find_devices_is_false
(
self
):
usb
=
hpib
.
P
ROLOGIX_GPIB_USB
(
findDevices
=
False
)
usb
=
hpib
.
P
rologixGpibUsb
(
findDevices
=
False
)
self
.
assertEqual
(
usb
.
getDevices
(),
'Not scanned.'
)
self
.
assertEqual
(
usb
.
getDevices
(),
'Not scanned.'
)
...
@@ -37,13 +37,13 @@ class PrologixGpibUsbTest(unittest.TestCase):
...
@@ -37,13 +37,13 @@ class PrologixGpibUsbTest(unittest.TestCase):
self
.
serial_mock
.
side_effect
=
SerialException
self
.
serial_mock
.
side_effect
=
SerialException
with
self
.
assertRaises
(
SerialException
):
with
self
.
assertRaises
(
SerialException
):
hpib
.
P
ROLOGIX_GPIB_USB
()
hpib
.
P
rologixGpibUsb
()
def
test_when_platform_linux_last_port_tried_is_ttyusb98
(
self
):
def
test_when_platform_linux_last_port_tried_is_ttyusb98
(
self
):
self
.
serial_mock
.
side_effect
=
SerialException
self
.
serial_mock
.
side_effect
=
SerialException
with
self
.
assertRaises
(
SerialException
):
with
self
.
assertRaises
(
SerialException
):
hpib
.
P
ROLOGIX_GPIB_USB
()
hpib
.
P
rologixGpibUsb
()
self
.
serial_mock
.
assert_called_with
(
'/dev/ttyUSB98'
,
timeout
=
1
)
self
.
serial_mock
.
assert_called_with
(
'/dev/ttyUSB98'
,
timeout
=
1
)
...
@@ -52,14 +52,14 @@ class PrologixGpibUsbTest(unittest.TestCase):
...
@@ -52,14 +52,14 @@ class PrologixGpibUsbTest(unittest.TestCase):
self
.
serial_mock
.
side_effect
=
SerialException
self
.
serial_mock
.
side_effect
=
SerialException
with
self
.
assertRaises
(
SerialException
):
with
self
.
assertRaises
(
SerialException
):
hpib
.
P
ROLOGIX_GPIB_USB
()
hpib
.
P
rologixGpibUsb
()
self
.
serial_mock
.
assert_called_with
(
'/dev/ttys998'
,
timeout
=
1
)
self
.
serial_mock
.
assert_called_with
(
'/dev/ttys998'
,
timeout
=
1
)
def
test_setup_device_when_port_found
(
self
):
def
test_setup_device_when_port_found
(
self
):
write_mock
=
self
.
serial_mock
.
return_value
.
write
write_mock
=
self
.
serial_mock
.
return_value
.
write
hpib
.
P
ROLOGIX_GPIB_USB
()
hpib
.
P
rologixGpibUsb
()
self
.
assertEqual
(
write_mock
.
call_args_list
[
0
],
call
(
"++savecfg 0"
+
chr
(
10
)))
self
.
assertEqual
(
write_mock
.
call_args_list
[
0
],
call
(
"++savecfg 0"
+
chr
(
10
)))
self
.
assertEqual
(
write_mock
.
call_args_list
[
1
],
call
(
"++auto 0"
+
chr
(
10
)))
self
.
assertEqual
(
write_mock
.
call_args_list
[
1
],
call
(
"++auto 0"
+
chr
(
10
)))
...
@@ -73,14 +73,14 @@ class PrologixGpibUsbTest(unittest.TestCase):
...
@@ -73,14 +73,14 @@ class PrologixGpibUsbTest(unittest.TestCase):
self
.
serial_mock
.
return_value
.
readline
.
return_value
=
""
self
.
serial_mock
.
return_value
.
readline
.
return_value
=
""
write_mock
=
self
.
serial_mock
.
return_value
.
write
write_mock
=
self
.
serial_mock
.
return_value
.
write
hpib
.
P
ROLOGIX_GPIB_USB
(
findDevices
=
True
)
hpib
.
P
rologixGpibUsb
(
findDevices
=
True
)
self
.
assertEqual
(
write_mock
.
call_args_list
[
7
],
self
.
assertEqual
(
write_mock
.
call_args_list
[
7
],
call
(
"++addr "
+
str
(
0
)
+
chr
(
10
)
+
"*idn?"
+
chr
(
10
)
+
"++read"
+
chr
(
10
)))
call
(
"++addr "
+
str
(
0
)
+
chr
(
10
)
+
"*idn?"
+
chr
(
10
)
+
"++read"
+
chr
(
10
)))
def
test_if_find_devices_getDevices_will_return_a_list_of_devices
(
self
):
def
test_if_find_devices_getDevices_will_return_a_list_of_devices
(
self
):
self
.
serial_mock
.
return_value
.
readline
.
return_value
=
"Device 1"
self
.
serial_mock
.
return_value
.
readline
.
return_value
=
"Device 1"
usb
=
hpib
.
P
ROLOGIX_GPIB_USB
(
findDevices
=
True
)
usb
=
hpib
.
P
rologixGpibUsb
(
findDevices
=
True
)
devices
=
usb
.
getDevices
()
devices
=
usb
.
getDevices
()
...
@@ -92,11 +92,11 @@ class PrologixGpibUsbTest(unittest.TestCase):
...
@@ -92,11 +92,11 @@ class PrologixGpibUsbTest(unittest.TestCase):
self
.
platform_mock
.
system
.
return_value
=
"Windows"
self
.
platform_mock
.
system
.
return_value
=
"Windows"
with
self
.
assertRaises
(
NotImplementedError
):
with
self
.
assertRaises
(
NotImplementedError
):
hpib
.
P
ROLOGIX_GPIB_USB
()
hpib
.
P
rologixGpibUsb
()
def
test_if_given_port_does_not_start_with_dev_tty_an_exception_is_raised
(
self
):
def
test_if_given_port_does_not_start_with_dev_tty_an_exception_is_raised
(
self
):
with
self
.
assertRaises
(
ValueError
):
with
self
.
assertRaises
(
ValueError
):
hpib
.
P
ROLOGIX_GPIB_USB
(
port
=
"device"
)
hpib
.
P
rologixGpibUsb
(
port
=
"device"
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment