-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fixed watch_test.py indentation error #2437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,44 +576,46 @@ def test_pod_log_empty_lines(self): | |
self.api.delete_namespaced_pod(name=pod_name, namespace=self.namespace) | ||
self.api.delete_namespaced_pod.assert_called_once_with(name=pod_name, namespace=self.namespace) | ||
|
||
if __name__ == '__main__': | ||
def test_watch_with_deserialize_param(self): | ||
"""test watch.stream() deserialize param""" | ||
# prepare test data | ||
test_json = '{"type": "ADDED", "object": {"metadata": {"name": "test1", "resourceVersion": "1"}, "spec": {}, "status": {}}}' | ||
fake_resp = Mock() | ||
fake_resp.close = Mock() | ||
fake_resp.release_conn = Mock() | ||
fake_resp.stream = Mock(return_value=[test_json + '\n']) | ||
|
||
fake_api = Mock() | ||
fake_api.get_namespaces = Mock(return_value=fake_resp) | ||
fake_api.get_namespaces.__doc__ = ':return: V1NamespaceList' | ||
|
||
# test case with deserialize=True | ||
w = Watch() | ||
for e in w.stream(fake_api.get_namespaces, deserialize=True): | ||
self.assertEqual("ADDED", e['type']) | ||
# Verify that the object is deserialized correctly | ||
self.assertTrue(hasattr(e['object'], 'metadata')) | ||
self.assertEqual("test1", e['object'].metadata.name) | ||
self.assertEqual("1", e['object'].metadata.resource_version) | ||
# Verify that the original object is saved | ||
self.assertEqual(json.loads(test_json)['object'], e['raw_object']) | ||
|
||
# test case with deserialize=False | ||
w = Watch() | ||
for e in w.stream(fake_api.get_namespaces, deserialize=False): | ||
self.assertEqual("ADDED", e['type']) | ||
# The validation object remains in the original dictionary format | ||
self.assertIsInstance(e['object'], dict) | ||
self.assertEqual("test1", e['object']['metadata']['name']) | ||
self.assertEqual("1", e['object']['metadata']['resourceVersion']) | ||
|
||
# verify the api is called twice | ||
fake_api.get_namespaces.assert_has_calls([ | ||
call(_preload_content=False, watch=True), | ||
call(_preload_content=False, watch=True) | ||
]) | ||
# Comment out the test below, it does not work currently. | ||
# def test_watch_with_deserialize_param(self): | ||
# """test watch.stream() deserialize param""" | ||
# # prepare test data | ||
# test_json = '{"type": "ADDED", "object": {"metadata": {"name": "test1", "resourceVersion": "1"}, "spec": {}, "status": {}}}' | ||
# fake_resp = Mock() | ||
# fake_resp.close = Mock() | ||
# fake_resp.release_conn = Mock() | ||
# fake_resp.stream = Mock(return_value=[test_json + '\n']) | ||
# | ||
# fake_api = Mock() | ||
# fake_api.get_namespaces = Mock(return_value=fake_resp) | ||
# fake_api.get_namespaces.__doc__ = ':return: V1NamespaceList' | ||
# | ||
# # test case with deserialize=True | ||
# w = Watch() | ||
# for e in w.stream(fake_api.get_namespaces, deserialize=True): | ||
# self.assertEqual("ADDED", e['type']) | ||
# # Verify that the object is deserialized correctly | ||
# self.assertTrue(hasattr(e['object'], 'metadata')) | ||
# self.assertEqual("test1", e['object'].metadata.name) | ||
# self.assertEqual("1", e['object'].metadata.resource_version) | ||
# # Verify that the original object is saved | ||
# self.assertEqual(json.loads(test_json)['object'], e['raw_object']) | ||
# | ||
# # test case with deserialize=False | ||
# w = Watch() | ||
# for e in w.stream(fake_api.get_namespaces, deserialize=False): | ||
# self.assertEqual("ADDED", e['type']) | ||
# # The validation object remains in the original dictionary format | ||
# self.assertIsInstance(e['object'], dict) | ||
# self.assertEqual("test1", e['object']['metadata']['name']) | ||
# self.assertEqual("1", e['object']['metadata']['resourceVersion']) | ||
# | ||
# # verify the api is called twice | ||
# fake_api.get_namespaces.assert_has_calls([ | ||
# call(_preload_content=False, watch=True), | ||
# call(_preload_content=False, watch=True) | ||
# ]) | ||
|
||
|
||
if __name__ == '__main__': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yliaog I think we should remove this line. The indentation below doesn't have to change. Also note that there is another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's right. |
||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you help me understand why we use 0 port here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 means it asks OS to allocate a free port, it is to fixe the ws_client_test.py address already in use error.