Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 4, 2023
1 parent 15af2f9 commit 91f38ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
3 changes: 1 addition & 2 deletions legate/util/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def extract_values(line: str) -> tuple[int, ...]:
return tuple(
sorted(
chain.from_iterable(
expand_range(r)
for r in line.strip().split(",")
expand_range(r) for r in line.strip().split(",")
)
)
)
54 changes: 30 additions & 24 deletions tests/unit/legate/util/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def test_gpus_osx(self) -> None:
with pytest.raises(RuntimeError, match=msg):
s.gpus

class Test_expand_range:

class Test_expand_range:
def test_errors(self) -> None:
msg = ""
with pytest.raises(ValueError):
Expand All @@ -123,12 +123,11 @@ def test_single_number(self, val) -> None:

@pytest.mark.parametrize("val", ("0-10", "1-2", "12-25"))
def test_range(self, val) -> None:
start, stop = val.split('-')
start, stop = val.split("-")
assert m.expand_range(val) == tuple(range(int(start), int(stop) + 1))


class Test_extract_values:

def test_errors(self) -> None:
msg = ""
with pytest.raises(ValueError):
Expand All @@ -139,40 +138,47 @@ def test_empty(self) -> None:

@pytest.mark.parametrize("val", ("0", "1,2", "3,5,7"))
def test_individual(self, val) -> None:
expected = {"0": (0,),
"1,2": (1, 2),
"3,5,7": (3, 5, 7),
}
expected = {
"0": (0,),
"1,2": (1, 2),
"3,5,7": (3, 5, 7),
}
assert m.extract_values(val) == expected[val]

@pytest.mark.parametrize("val", ("2,1", "8,5,3,2", "1,3,2,5,4,7,6"))
def test_individual_ordered(self, val) -> None:
expected = {"2,1": (1, 2),
"8,5,3,2": (2, 3, 5, 8),
"1,3,2,5,4,7,6": (1, 2, 3, 4, 5, 6, 7),
}
expected = {
"2,1": (1, 2),
"8,5,3,2": (2, 3, 5, 8),
"1,3,2,5,4,7,6": (1, 2, 3, 4, 5, 6, 7),
}
assert m.extract_values(val) == expected[val]

@pytest.mark.parametrize("val", ("0-2", "0-2,4-5", "0-1,3-5,8-11"))
def test_range(self, val) -> None:
expected = {"0-2": (0, 1, 2),
"0-2,4-5": (0, 1, 2, 4, 5),
"0-1,3-5,8-11": (0, 1, 3, 4, 5, 8, 9, 10 ,11),
}
expected = {
"0-2": (0, 1, 2),
"0-2,4-5": (0, 1, 2, 4, 5),
"0-1,3-5,8-11": (0, 1, 3, 4, 5, 8, 9, 10, 11),
}
assert m.extract_values(val) == expected[val]

@pytest.mark.parametrize("val", ("2-3,0-1", "0-1,4-5,2-3"))
def test_range_ordered(self, val) -> None:
expected = {"2-3,0-1": (0, 1, 2, 3),
"0-1,4-5,2-3": (0, 1, 2, 3, 4, 5),
}
expected = {
"2-3,0-1": (0, 1, 2, 3),
"0-1,4-5,2-3": (0, 1, 2, 3, 4, 5),
}
assert m.extract_values(val) == expected[val]

@pytest.mark.parametrize("val", ("0,1-2", "1-2,0", "0,1-2,3,4-5,6", "5-6,4,1-3,0"))
@pytest.mark.parametrize(
"val", ("0,1-2", "1-2,0", "0,1-2,3,4-5,6", "5-6,4,1-3,0")
)
def test_mixed(self, val) -> None:
expected = {"0,1-2": (0, 1, 2),
"1-2,0": (0, 1, 2),
"0,1-2,3,4-5,6": (0, 1, 2, 3, 4, 5, 6),
"5-6,4,1-3,0": (0, 1, 2, 3, 4, 5, 6),
}
expected = {
"0,1-2": (0, 1, 2),
"1-2,0": (0, 1, 2),
"0,1-2,3,4-5,6": (0, 1, 2, 3, 4, 5, 6),
"5-6,4,1-3,0": (0, 1, 2, 3, 4, 5, 6),
}
assert m.extract_values(val) == expected[val]

0 comments on commit 91f38ef

Please sign in to comment.