From 2b7259949c0fd43ea6e2078d33ffb886c78a94f5 Mon Sep 17 00:00:00 2001 From: Justin Kiggins Date: Wed, 11 Jul 2018 13:00:32 -0700 Subject: [PATCH 1/6] make hosts all lowercase --- visual_behavior/devices.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/visual_behavior/devices.py b/visual_behavior/devices.py index 89a9adb5f..f57615e54 100644 --- a/visual_behavior/devices.py +++ b/visual_behavior/devices.py @@ -50,6 +50,8 @@ 'localhost': 'localhost' } +RIG_NAME = {k.lower(): v for k, v in iteritems(RIG_NAME)) + COMPUTER_NAME = dict((v, k) for k, v in iteritems(RIG_NAME)) @@ -71,7 +73,7 @@ def get_rig_id(in_val, input_type='computer_name'): specifies whether `in_val` is a computer name or rig_id ''' if input_type == 'computer_name' and in_val in RIG_NAME.keys(): - return RIG_NAME[in_val] + return RIG_NAME[in_val.lower()] elif input_type == 'rig_id' and in_val in COMPUTER_NAME.keys(): return COMPUTER_NAME[in_val] else: From 85dcc4ed74752d81c221d30b882c4321a35885e6 Mon Sep 17 00:00:00 2001 From: Justin Kiggins Date: Wed, 11 Jul 2018 21:17:34 -0700 Subject: [PATCH 2/6] fix close bracket --- visual_behavior/devices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visual_behavior/devices.py b/visual_behavior/devices.py index f57615e54..1eb0e5e11 100644 --- a/visual_behavior/devices.py +++ b/visual_behavior/devices.py @@ -50,7 +50,7 @@ 'localhost': 'localhost' } -RIG_NAME = {k.lower(): v for k, v in iteritems(RIG_NAME)) +RIG_NAME = {k.lower(): v for k, v in iteritems(RIG_NAME)} COMPUTER_NAME = dict((v, k) for k, v in iteritems(RIG_NAME)) From cf40b41dc8dda705b5530eac8700da9aaec04e42 Mon Sep 17 00:00:00 2001 From: Justin Kiggins Date: Wed, 11 Jul 2018 21:28:53 -0700 Subject: [PATCH 3/6] updates tests --- tests/test_devices.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_devices.py b/tests/test_devices.py index 7a01d8f7e..71661a17a 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -5,7 +5,8 @@ @pytest.mark.parametrize("kwargs, expected", [ ({"in_val": "W7DTMJ19R2F", "input_type": "computer_name", }, "A1", ), - ({"in_val": "A2", "input_type": "rig_id", }, "W7DTMJ35Y0T", ), + ({"in_val": "w7dtmj19r2f", "input_type": "computer_name", }, "A1", ), + ({"in_val": "A2", "input_type": "rig_id", }, "w7dtmj35y0t", ), ({"in_val": "NOT_A_NAME", "input_type": "computer_name", }, "unknown", ), ]) def test_get_rid_id(kwargs, expected): From 9674fb2869ebf628a13b738e68bc9f866d7f53c8 Mon Sep 17 00:00:00 2001 From: Justin Kiggins Date: Wed, 11 Jul 2018 21:37:49 -0700 Subject: [PATCH 4/6] Update devices.py --- visual_behavior/devices.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/visual_behavior/devices.py b/visual_behavior/devices.py index 1eb0e5e11..7c84fcfb9 100644 --- a/visual_behavior/devices.py +++ b/visual_behavior/devices.py @@ -56,25 +56,32 @@ # -> devices.py -def get_rig_id(in_val, input_type='computer_name'): +def get_rig_id(computer_name): ''' This provides a map between the computer name and the rig ID. >>> get_rig_id('W7DTMJ19R2F') A1 - >>> get_rig_id('A1',input_type='rig_id') - W7DTMJ19R2F - + Parameters ---------- in_val : str computer name - input_type : 'computer_name' or 'rig_id' - specifies whether `in_val` is a computer name or rig_id ''' - if input_type == 'computer_name' and in_val in RIG_NAME.keys(): - return RIG_NAME[in_val.lower()] - elif input_type == 'rig_id' and in_val in COMPUTER_NAME.keys(): - return COMPUTER_NAME[in_val] - else: - return 'unknown' + + return RIG_NAME.get(computer_name.lower(),'unknown') + +def get_computer_name(rig_id): + ''' + This provides a map between the computer name and the rig ID. + + >>> get_computer_name('A1') + W7DTMJ19R2F + + Parameters + ---------- + rig_id : str + rig name + ''' + + return COMPUTER_NAME.get(rig_id,'unknown') From 24ece8275b48ac1766fec049e9caa893b161a974 Mon Sep 17 00:00:00 2001 From: Justin Kiggins Date: Wed, 11 Jul 2018 21:41:55 -0700 Subject: [PATCH 5/6] refactor device lookup --- tests/test_devices.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/test_devices.py b/tests/test_devices.py index 71661a17a..5d792826c 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -3,11 +3,18 @@ from visual_behavior import devices -@pytest.mark.parametrize("kwargs, expected", [ - ({"in_val": "W7DTMJ19R2F", "input_type": "computer_name", }, "A1", ), - ({"in_val": "w7dtmj19r2f", "input_type": "computer_name", }, "A1", ), - ({"in_val": "A2", "input_type": "rig_id", }, "w7dtmj35y0t", ), - ({"in_val": "NOT_A_NAME", "input_type": "computer_name", }, "unknown", ), +@pytest.mark.parametrize("computer_name, rig_id", [ + ("W7DTMJ19R2F", "A1"), + ("w7dtmj19r2f", "A1"), + ("NOT_A_NAME", "unknown"), ]) -def test_get_rid_id(kwargs, expected): - assert devices.get_rig_id(**kwargs) == expected +def test_get_rid_id(computer_name, rig_id): + assert devices.get_rig_id(computer_name) == rig_id + + +@pytest.mark.parametrize("rig_id, computer_name", [ + ("A2","w7dtmj35y0t"), + ("NOT_A_RIG", "unknown"), +]) +def test_get_computer_name(rig_id, computer_name): + assert devices.get_computer_name(rig_id) == computer_name From 4e5d021e1d3fb55f1ab0ece44e205f732ef4c0cc Mon Sep 17 00:00:00 2001 From: Justin Kiggins Date: Wed, 11 Jul 2018 21:49:31 -0700 Subject: [PATCH 6/6] fix style --- visual_behavior/devices.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/visual_behavior/devices.py b/visual_behavior/devices.py index 7c84fcfb9..53c0aa88a 100644 --- a/visual_behavior/devices.py +++ b/visual_behavior/devices.py @@ -62,14 +62,15 @@ def get_rig_id(computer_name): >>> get_rig_id('W7DTMJ19R2F') A1 - + Parameters ---------- in_val : str computer name ''' - - return RIG_NAME.get(computer_name.lower(),'unknown') + + return RIG_NAME.get(computer_name.lower(), 'unknown') + def get_computer_name(rig_id): ''' @@ -83,5 +84,5 @@ def get_computer_name(rig_id): rig_id : str rig name ''' - - return COMPUTER_NAME.get(rig_id,'unknown') + + return COMPUTER_NAME.get(rig_id, 'unknown')