Skip to content

Commit

Permalink
Merge 23f5cad into b978d00
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-stokes committed May 17, 2019
2 parents b978d00 + 23f5cad commit d1e5408
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ def __deepcopy__(self, memo):
copy.deepcopy(self.items()))

def __repr__(self):
return 'OrderedDefaultDict(%s, %s)' % (self.default_factory,
OrderedDict.__repr__(self))
return 'OrderedDefaultDict(%s, %s)' % (
self.default_factory, OrderedDict.__repr__(self))
10 changes: 10 additions & 0 deletions spinn_utilities/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


class SpiNNUtilsException(Exception):
""" Superclass of all exceptions from the SpiNNUtils module.
"""


class FailedToFindBinaryException(SpiNNUtilsException):
""" Raised when the executable finder cant find the binary
"""
14 changes: 9 additions & 5 deletions spinn_utilities/executable_finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os

from spinn_utilities.exceptions import FailedToFindBinaryException
from .ordered_set import OrderedSet


Expand Down Expand Up @@ -56,20 +58,22 @@ def get_executable_path(self, executable_name):
return potential_filename

# No executable found
return None
raise FailedToFindBinaryException(
"failed to locate binary for {}. Fix and try again".format(
executable_name))

def get_executable_paths(self, executable_names):
""" Finds each executables within the set of folders.\
The names are assumed to be comma seperated
The names are assumed to be comma separated
The set of folders is searched sequentially\
and the first match for each name is returned.
Names not found are ignored and not added to the list.
:param executable_name: The name of the executable to find.\
Assumed to be comma seperated.
:type executable_name: str
:param executable_names: The name of the executable to find.\
Assumed to be comma separated.
:type executable_names: str
:return:\
The full path of the discovered executable, or ``None`` if no \
executable was found in the set of folders
Expand Down
2 changes: 1 addition & 1 deletion spinn_utilities/find_max_success.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def search_for_max_success(best_success, min_fail, check):
whole range fails or is empty.
"""
# Check if there are still values in the middle to check
if (best_success >= min_fail - 1):
if best_success >= min_fail - 1:
return best_success
# Find the middle
mid_point = (best_success + min_fail) // 2
Expand Down
9 changes: 7 additions & 2 deletions unittests/test_exec_finder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest

from spinn_utilities.exceptions import FailedToFindBinaryException
from spinn_utilities.executable_finder import ExecutableFinder


Expand All @@ -13,7 +16,8 @@ def test_create_and_config(tmpdir):

def test_find_in_no_places():
ef = ExecutableFinder([])
assert ef.get_executable_path("abc.aplx") is None
with pytest.raises(FailedToFindBinaryException):
ef.get_executable_path("abc.aplx")


def test_find_in_one_place(tmpdir):
Expand All @@ -39,7 +43,8 @@ def test_find_in_two_places(tmpdir):
w2.remove()
assert ef.get_executable_path("abc.aplx") == str(w1)
w1.remove()
assert ef.get_executable_path("abc.aplx") is None
with pytest.raises(FailedToFindBinaryException):
ef.get_executable_path("abc.aplx")


def test_find_no_duplicates(tmpdir):
Expand Down
4 changes: 2 additions & 2 deletions unittests/test_ordered_default_dict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from spinn_utilities.ordered_default_dict import DefaultOrderedDict
from spinn_utilities.default_ordered_dict import DefaultOrderedDict
from spinn_utilities.ordered_set import OrderedSet


Expand All @@ -21,7 +21,7 @@ def test_list_default():
assert o["bar"] == 2


def test_orderedset_default():
def test_ordered_set_default():
o = DefaultOrderedDict(OrderedSet)
assert o is not None
o["foo"].add(2)
Expand Down

0 comments on commit d1e5408

Please sign in to comment.