Skip to content

Commit

Permalink
Add environment variable option for lpt arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Boerboom committed Dec 14, 2017
1 parent 5d8093e commit dfa16a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions distributed_nose/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def options(self, parser, env):
"hash-ring",
"least-processing-time"
),
default="hash-ring",
default=env.get('NOSE_DISTRIBUTION_ALGORITHM', "hash-ring"),
metavar="ALGORITHM",
help=(
"Specify an algorithm [hash-ring|least-processing-time] "
Expand All @@ -100,6 +100,7 @@ def options(self, parser, env):
"--lpt-data",
action="store",
dest="lpt_data_filepath",
default=env.get('NOSE_LPT_DATA_FILEPATH'),
help=(
"The filepath from which to retrieve the data to use for "
"the least processing time algorithm. Required when "
Expand Down Expand Up @@ -156,13 +157,13 @@ def configure(self, options, config):
reverse=True
)

for cls, data in sorted_lpt_data:
for c, data in sorted_lpt_data:
node = min(
self.lpt_nodes[1:],
key=lambda n: n['processing_time']
)
node['processing_time'] += data['duration']
node['classes'].add(cls)
node['classes'].add(c)

except IOError:
logger.critical(
Expand Down Expand Up @@ -249,7 +250,8 @@ def wantClass(self, cls):
# only if we were given the classes for consideration in
# the same order across all nodes).
node = self.hash_ring.get_node(str(cls))
return node == self.node_id
if node != self.node_id:
return False

return None

Expand Down
1 change: 1 addition & 0 deletions tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_only_largest_included(self):
)

self.assertTrue(len(classes) == 1)
# TODO: make compatible with python 2.6 ?
self.assertIn('TC5', classes)

# Function selection should not have changed.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_lpt_no_data_arg_aborts(self):
]
options, _ = self.parser.parse_args(args)

# TODO: make compatible with python 2.6 ?
with self.assertRaises(AssertionError):
self.plugin.configure(options, Config())

Expand All @@ -139,6 +140,7 @@ def test_lpt_missing_data_file_aborts(self):
]
options, _ = self.parser.parse_args(args)

# TODO: make compatible with python 2.6 ?
with self.assertRaises(IOError):
self.plugin.configure(options, Config())

Expand All @@ -157,6 +159,7 @@ def test_lpt_invalid_json_file_aborts(self):
]
options, _ = self.parser.parse_args(args)

# TODO: make compatible with python 2.6 ?
with self.assertRaises(ValueError):
self.plugin.configure(options, Config())

Expand All @@ -175,5 +178,6 @@ def test_lpt_invalid_data_format_aborts(self):
]
options, _ = self.parser.parse_args(args)

# TODO: make compatible with python 2.6 ?
with self.assertRaises(KeyError):
self.plugin.configure(options, Config())

0 comments on commit dfa16a2

Please sign in to comment.