Skip to content

Commit

Permalink
[datasets] Add startswith() and endswith() to Benchmark class.
Browse files Browse the repository at this point in the history
This provides methods to forward startswith() and endswith() calls to
the underlying string representation.
  • Loading branch information
ChrisCummins committed Jan 27, 2022
1 parent 01cb0be commit 78783a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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
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 78783a0

Please sign in to comment.