Skip to content

Commit

Permalink
Merge pull request #555 from ChrisCummins/fix/benchmark-uri
Browse files Browse the repository at this point in the history
[datasets] Small benchmark URI fix and tweak
  • Loading branch information
ChrisCummins authored Feb 7, 2022
2 parents 9eaafb2 + 78783a0 commit 67ff153
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions compiler_gym/datasets/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def from_string(cls, uri: str) -> "BenchmarkUri":
fragment=components.fragment,
)

def startswith(self, *args):
return str(self).startswith(*args)

def endswith(self, *args):
return str(self).endswith(*args)

def __repr__(self):
return urlunparse(
ParseResult(
Expand Down
2 changes: 1 addition & 1 deletion examples/example_compiler_gym_service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, *args, **kwargs):
def benchmark_uris(self) -> Iterable[str]:
yield from (f"benchmark://example-v0{k}" for k in self._benchmarks.keys())

def benchmark_from_parsed_uris(self, uri: BenchmarkUri) -> Benchmark:
def benchmark_from_parsed_uri(self, uri: BenchmarkUri) -> Benchmark:
if uri.path in self._benchmarks:
return self._benchmarks[uri]
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/datasets/uri_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,19 @@ def test_canonicalize_1():
assert BenchmarkUri.canonicalize("test-v0") == "benchmark://test-v0"


def test_startswith():
uri = BenchmarkUri.from_string("benchmark://test-v0/foo")
assert not uri.startswith("!!!")
assert uri.startswith("b")
assert uri.startswith("benchmark://test-v0/fo")


def test_endswith():
uri = BenchmarkUri.from_string("benchmark://test-v0/foo")
assert not uri.endswith("!!!")
assert uri.endswith("o")
assert uri.endswith("mark://test-v0/foo")


if __name__ == "__main__":
main()

0 comments on commit 67ff153

Please sign in to comment.