Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: client/libs/logdog/tests/streamname_test.py

Issue 2243483003: Add LogDog stream name normalization function. (Closed) Base URL: https://github.com/luci/luci-py@master
Patch Set: Use string constants. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/libs/logdog/streamname.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/libs/logdog/tests/streamname_test.py
diff --git a/client/libs/logdog/tests/streamname_test.py b/client/libs/logdog/tests/streamname_test.py
index f5898a4fe02825e83dc9dfa73a360646aa37bb52..c84292a6554a30417868d8ed57089a6afd84c422 100755
--- a/client/libs/logdog/tests/streamname_test.py
+++ b/client/libs/logdog/tests/streamname_test.py
@@ -43,6 +43,24 @@ class StreamNameTestCase(unittest.TestCase):
raised = True
self.assertFalse(raised, "Stream name '%s' raised ValueError" % (name,))
+ def testNormalize(self):
+ for name, normalized in (
+ ('', 'PFX'),
+ ('_invalid_start_char', 'PFX_invalid_start_char'),
+ ('valid_stream_name.1:2-3', 'valid_stream_name.1:2-3'),
+ ('some stream (with stuff)', 'some_stream__with_stuff_'),
+ ('_invalid/st!ream/name entry', 'PFX_invalid/st_ream/name_entry'),
+ (' ', 'PFX_____'),
+ ):
+ self.assertEqual(streamname.normalize(name, prefix='PFX'), normalized)
+
+ # Assert that an empty stream name with no prefix will raise a ValueError.
+ self.assertRaises(ValueError, streamname.normalize, '')
+
+ # Assert that a stream name with an invalid starting character and no prefix
+ # will raise a ValueError.
+ self.assertRaises(ValueError, streamname.normalize, '_invalid_start_char')
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « client/libs/logdog/streamname.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698