Skip to content

Commit cd1518f

Browse files
authored
Merge pull request #269 from AllenInstitute/feature/lowercase_hostnames
make hosts all lowercase
2 parents 891c88c + 204d710 commit cd1518f

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

tests/test_devices.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
from visual_behavior import devices
44

55

6-
@pytest.mark.parametrize("kwargs, expected", [
7-
({"in_val": "W7DTMJ19R2F", "input_type": "computer_name", }, "A1", ),
8-
({"in_val": "A2", "input_type": "rig_id", }, "W7DTMJ35Y0T", ),
9-
({"in_val": "NOT_A_NAME", "input_type": "computer_name", }, "unknown", ),
6+
@pytest.mark.parametrize("computer_name, rig_id", [
7+
("W7DTMJ19R2F", "A1"),
8+
("w7dtmj19r2f", "A1"),
9+
("NOT_A_NAME", "unknown"),
1010
])
11-
def test_get_rid_id(kwargs, expected):
12-
assert devices.get_rig_id(**kwargs) == expected
11+
def test_get_rid_id(computer_name, rig_id):
12+
assert devices.get_rig_id(computer_name) == rig_id
13+
14+
15+
@pytest.mark.parametrize("rig_id, computer_name", [
16+
("A2","w7dtmj35y0t"),
17+
("NOT_A_RIG", "unknown"),
18+
])
19+
def test_get_computer_name(rig_id, computer_name):
20+
assert devices.get_computer_name(rig_id) == computer_name

visual_behavior/devices.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,39 @@
5151
'localhost': 'localhost'
5252
}
5353

54+
RIG_NAME = {k.lower(): v for k, v in iteritems(RIG_NAME)}
55+
5456
COMPUTER_NAME = dict((v, k) for k, v in iteritems(RIG_NAME))
5557

5658

5759
# -> devices.py
58-
def get_rig_id(in_val, input_type='computer_name'):
60+
def get_rig_id(computer_name):
5961
'''
6062
This provides a map between the computer name and the rig ID.
6163
6264
>>> get_rig_id('W7DTMJ19R2F')
6365
A1
64-
>>> get_rig_id('A1',input_type='rig_id')
65-
W7DTMJ19R2F
6666
6767
Parameters
6868
----------
6969
in_val : str
7070
computer name
71-
input_type : 'computer_name' or 'rig_id'
72-
specifies whether `in_val` is a computer name or rig_id
7371
'''
74-
if input_type == 'computer_name' and in_val in RIG_NAME.keys():
75-
return RIG_NAME[in_val]
76-
elif input_type == 'rig_id' and in_val in COMPUTER_NAME.keys():
77-
return COMPUTER_NAME[in_val]
78-
else:
79-
return 'unknown'
72+
73+
return RIG_NAME.get(computer_name.lower(), 'unknown')
74+
75+
76+
def get_computer_name(rig_id):
77+
'''
78+
This provides a map between the computer name and the rig ID.
79+
80+
>>> get_computer_name('A1')
81+
W7DTMJ19R2F
82+
83+
Parameters
84+
----------
85+
rig_id : str
86+
rig name
87+
'''
88+
89+
return COMPUTER_NAME.get(rig_id, 'unknown')

0 commit comments

Comments
 (0)