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

Unified Diff: mojo/python/tests/system_unittest.py

Issue 522483006: mojo: Update python API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow review Created 6 years, 3 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 | « mojo/python/system/mojo/embedder.pyx ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/python/tests/system_unittest.py
diff --git a/mojo/python/tests/system_unittest.py b/mojo/python/tests/system_unittest.py
index 46dde470f32d4ef910dc342b3dd090c601ad64dd..2f0e36a3c19520366f8d0e22624ad08487ab3819 100644
--- a/mojo/python/tests/system_unittest.py
+++ b/mojo/python/tests/system_unittest.py
@@ -8,13 +8,13 @@ import time
import unittest
# pylint: disable=F0401
-from mojo.embedder import init as init_embedder
+import mojo.embedder
from mojo import system
DATA_SIZE = 1024
-def get_random_buffer(size):
+def _GetRandomBuffer(size):
random.seed(size)
return bytearray(''.join(chr(random.randint(0, 255)) for i in xrange(size)))
@@ -22,12 +22,12 @@ def get_random_buffer(size):
class BaseMojoTest(unittest.TestCase):
def setUp(self):
- init_embedder()
+ mojo.embedder.Init()
class CoreTest(BaseMojoTest):
- def test_results(self):
+ def testResults(self):
self.assertEquals(system.RESULT_OK, 0)
self.assertLess(system.RESULT_CANCELLED, 0)
self.assertLess(system.RESULT_UNKNOWN, 0)
@@ -47,7 +47,7 @@ class CoreTest(BaseMojoTest):
self.assertLess(system.RESULT_BUSY, 0)
self.assertLess(system.RESULT_SHOULD_WAIT, 0)
- def test_constants(self):
+ def testConstants(self):
self.assertGreaterEqual(system.DEADLINE_INDEFINITE, 0)
self.assertGreaterEqual(system.HANDLE_SIGNAL_NONE, 0)
self.assertGreaterEqual(system.HANDLE_SIGNAL_READABLE, 0)
@@ -63,111 +63,111 @@ class CoreTest(BaseMojoTest):
self.assertGreaterEqual(system.READ_DATA_FLAG_QUERY, 0)
self.assertGreaterEqual(system.MAP_BUFFER_FLAG_NONE, 0)
- def test_get_time_ticks_now(self):
+ def testGetTimeTicksNow(self):
pt1 = time.time()
- v1 = system.get_time_ticks_now()
+ v1 = system.GetTimeTicksNow()
time.sleep(1e-3)
- v2 = system.get_time_ticks_now()
+ v2 = system.GetTimeTicksNow()
pt2 = time.time()
self.assertGreater(v1, 0)
self.assertGreater(v2, v1 + 1000)
self.assertGreater(1e6 * (pt2 - pt1), v2 - v1)
- def _test_handles_creation(self, *args):
+ def _testHandlesCreation(self, *args):
for handle in args:
- self.assertTrue(handle.is_valid())
- handle.close()
- self.assertFalse(handle.is_valid())
+ self.assertTrue(handle.IsValid())
+ handle.Close()
+ self.assertFalse(handle.IsValid())
- def _test_message_handle_creation(self, handles):
- self._test_handles_creation(handles.handle0, handles.handle1)
+ def _TestMessageHandleCreation(self, handles):
+ self._testHandlesCreation(handles.handle0, handles.handle1)
- def test_create_message_pipe(self):
- self._test_message_handle_creation(system.MessagePipe())
+ def testCreateMessagePipe(self):
+ self._TestMessageHandleCreation(system.MessagePipe())
- def test_create_message_pipe_with_none_options(self):
- self._test_message_handle_creation(system.MessagePipe(None))
+ def testCreateMessagePipeWithNoneOptions(self):
+ self._TestMessageHandleCreation(system.MessagePipe(None))
- def test_create_message_pipe_with_options(self):
- self._test_message_handle_creation(
+ def testCreateMessagePipeWithOptions(self):
+ self._TestMessageHandleCreation(
system.MessagePipe(system.CreateMessagePipeOptions()))
- def test_wait_over_message_pipe(self):
+ def testWaitOverMessagePipe(self):
handles = system.MessagePipe()
handle = handles.handle0
- self.assertEquals(system.RESULT_OK, handle.wait(
+ self.assertEquals(system.RESULT_OK, handle.Wait(
system.HANDLE_SIGNAL_WRITABLE, system.DEADLINE_INDEFINITE))
self.assertEquals(system.RESULT_DEADLINE_EXCEEDED,
- handle.wait(system.HANDLE_SIGNAL_READABLE, 0))
+ handle.Wait(system.HANDLE_SIGNAL_READABLE, 0))
- handles.handle1.write_message()
+ handles.handle1.WriteMessage()
self.assertEquals(
system.RESULT_OK,
- handle.wait(
+ handle.Wait(
system.HANDLE_SIGNAL_READABLE,
system.DEADLINE_INDEFINITE))
- def test_wait_over_many_message_pipe(self):
+ def testWaitOverManyMessagePipe(self):
handles = system.MessagePipe()
handle0 = handles.handle0
handle1 = handles.handle1
self.assertEquals(
0,
- system.wait_many(
+ system.WaitMany(
[(handle0, system.HANDLE_SIGNAL_WRITABLE),
(handle1, system.HANDLE_SIGNAL_WRITABLE)],
system.DEADLINE_INDEFINITE))
self.assertEquals(
system.RESULT_DEADLINE_EXCEEDED,
- system.wait_many(
+ system.WaitMany(
[(handle0, system.HANDLE_SIGNAL_READABLE),
(handle1, system.HANDLE_SIGNAL_READABLE)], 0))
- handle0.write_message()
+ handle0.WriteMessage()
self.assertEquals(
1,
- system.wait_many(
+ system.WaitMany(
[(handle0, system.HANDLE_SIGNAL_READABLE),
(handle1, system.HANDLE_SIGNAL_READABLE)],
system.DEADLINE_INDEFINITE))
- def test_send_bytes_over_message_pipe(self):
+ def testSendBytesOverMessagePipe(self):
handles = system.MessagePipe()
- data = get_random_buffer(DATA_SIZE)
- handles.handle0.write_message(data)
- (res, buffers, next_message) = handles.handle1.read_message()
+ data = _GetRandomBuffer(DATA_SIZE)
+ handles.handle0.WriteMessage(data)
+ (res, buffers, next_message) = handles.handle1.ReadMessage()
self.assertEquals(system.RESULT_RESOURCE_EXHAUSTED, res)
self.assertEquals(None, buffers)
self.assertEquals((DATA_SIZE, 0), next_message)
result = bytearray(DATA_SIZE)
- (res, buffers, next_message) = handles.handle1.read_message(result)
+ (res, buffers, next_message) = handles.handle1.ReadMessage(result)
self.assertEquals(system.RESULT_OK, res)
self.assertEquals(None, next_message)
self.assertEquals((data, []), buffers)
- def test_send_empty_data_over_message_pipe(self):
+ def testSendEmptyDataOverMessagePipe(self):
handles = system.MessagePipe()
- handles.handle0.write_message(None)
- (res, buffers, next_message) = handles.handle1.read_message()
+ handles.handle0.WriteMessage(None)
+ (res, buffers, next_message) = handles.handle1.ReadMessage()
self.assertEquals(system.RESULT_OK, res)
self.assertEquals(None, next_message)
self.assertEquals((None, []), buffers)
- def test_send_handle_over_message_pipe(self):
+ def testSendHandleOverMessagePipe(self):
handles = system.MessagePipe()
handles_to_send = system.MessagePipe()
- handles.handle0.write_message(handles=[handles_to_send.handle0,
+ handles.handle0.WriteMessage(handles=[handles_to_send.handle0,
handles_to_send.handle1])
- (res, buffers, next_message) = handles.handle1.read_message(
+ (res, buffers, next_message) = handles.handle1.ReadMessage(
max_number_of_handles=2)
- self.assertFalse(handles_to_send.handle0.is_valid())
- self.assertFalse(handles_to_send.handle1.is_valid())
+ self.assertFalse(handles_to_send.handle0.IsValid())
+ self.assertFalse(handles_to_send.handle1.IsValid())
self.assertEquals(system.RESULT_OK, res)
self.assertEquals(None, next_message)
self.assertEquals(None, buffers[0])
@@ -175,121 +175,121 @@ class CoreTest(BaseMojoTest):
handles = buffers[1]
for handle in handles:
- self.assertTrue(handle.is_valid())
- (res, buffers, next_message) = handle.read_message()
+ self.assertTrue(handle.IsValid())
+ (res, buffers, next_message) = handle.ReadMessage()
self.assertEquals(system.RESULT_SHOULD_WAIT, res)
for handle in handles:
- handle.write_message()
+ handle.WriteMessage()
for handle in handles:
- (res, buffers, next_message) = handle.read_message()
+ (res, buffers, next_message) = handle.ReadMessage()
self.assertEquals(system.RESULT_OK, res)
- def _test_data_handle_creation(self, handles):
- self._test_handles_creation(
+ def _TestDataHandleCreation(self, handles):
+ self._testHandlesCreation(
handles.producer_handle, handles.consumer_handle)
- def test_create_data_pipe(self):
- self._test_data_handle_creation(system.DataPipe())
+ def testCreateDataPipe(self):
+ self._TestDataHandleCreation(system.DataPipe())
- def test_create_data_pipe_with_none_options(self):
- self._test_data_handle_creation(system.DataPipe(None))
+ def testCreateDataPipeWithNoneOptions(self):
+ self._TestDataHandleCreation(system.DataPipe(None))
- def test_create_data_pipe_with_default_options(self):
- self._test_data_handle_creation(
+ def testCreateDataPipeWithDefaultOptions(self):
+ self._TestDataHandleCreation(
system.DataPipe(system.CreateDataPipeOptions()))
- def test_create_data_pipe_with_discard_flag(self):
+ def testCreateDataPipeWithDiscardFlag(self):
options = system.CreateDataPipeOptions()
options.flags = system.CreateDataPipeOptions.FLAG_MAY_DISCARD
- self._test_data_handle_creation(system.DataPipe(options))
+ self._TestDataHandleCreation(system.DataPipe(options))
- def test_create_data_pipe_with_element_size(self):
+ def testCreateDataPipeWithElementSize(self):
options = system.CreateDataPipeOptions()
options.element_num_bytes = 5
- self._test_data_handle_creation(system.DataPipe(options))
+ self._TestDataHandleCreation(system.DataPipe(options))
- def test_create_data_pipe_with_capacity(self):
+ def testCreateDataPipeWithCapacity(self):
options = system.CreateDataPipeOptions()
options.element_capacity_num_bytes = DATA_SIZE
- self._test_data_handle_creation(system.DataPipe(options))
+ self._TestDataHandleCreation(system.DataPipe(options))
- def test_create_data_pipe_with_incorrect_parameters(self):
+ def testCreateDataPipeWithIncorrectParameters(self):
options = system.CreateDataPipeOptions()
options.element_num_bytes = 5
options.capacity_num_bytes = DATA_SIZE
with self.assertRaises(system.MojoException) as cm:
- self._test_data_handle_creation(system.DataPipe(options))
+ self._TestDataHandleCreation(system.DataPipe(options))
self.assertEquals(system.RESULT_INVALID_ARGUMENT, cm.exception.mojo_result)
- def test_send_empty_data_over_data_pipe(self):
+ def testSendEmptyDataOverDataPipe(self):
pipes = system.DataPipe()
- self.assertEquals((system.RESULT_OK, 0), pipes.producer_handle.write_data())
+ self.assertEquals((system.RESULT_OK, 0), pipes.producer_handle.WriteData())
self.assertEquals(
- (system.RESULT_OK, None), pipes.consumer_handle.read_data())
+ (system.RESULT_OK, None), pipes.consumer_handle.ReadData())
- def test_send_data_over_data_pipe(self):
+ def testSendDataOverDataPipe(self):
pipes = system.DataPipe()
- data = get_random_buffer(DATA_SIZE)
+ data = _GetRandomBuffer(DATA_SIZE)
self.assertEquals((system.RESULT_OK, DATA_SIZE),
- pipes.producer_handle.write_data(data))
+ pipes.producer_handle.WriteData(data))
self.assertEquals((system.RESULT_OK, data),
- pipes.consumer_handle.read_data(bytearray(DATA_SIZE)))
+ pipes.consumer_handle.ReadData(bytearray(DATA_SIZE)))
- def test_two_phase_write_on_data_pipe(self):
+ def testTwoPhaseWriteOnDataPipe(self):
pipes = system.DataPipe()
- (res, buf) = pipes.producer_handle.begin_write_data(DATA_SIZE)
+ (res, buf) = pipes.producer_handle.BeginWriteData(DATA_SIZE)
self.assertEquals(system.RESULT_OK, res)
self.assertGreaterEqual(len(buf.buffer), DATA_SIZE)
- data = get_random_buffer(DATA_SIZE)
+ data = _GetRandomBuffer(DATA_SIZE)
buf.buffer[0:DATA_SIZE] = data
- self.assertEquals(system.RESULT_OK, buf.end(DATA_SIZE))
+ self.assertEquals(system.RESULT_OK, buf.End(DATA_SIZE))
self.assertEquals((system.RESULT_OK, data),
- pipes.consumer_handle.read_data(bytearray(DATA_SIZE)))
+ pipes.consumer_handle.ReadData(bytearray(DATA_SIZE)))
- def test_two_phase_read_on_data_pipe(self):
+ def testTwoPhaseReadOnDataPipe(self):
pipes = system.DataPipe()
- data = get_random_buffer(DATA_SIZE)
+ data = _GetRandomBuffer(DATA_SIZE)
self.assertEquals((system.RESULT_OK, DATA_SIZE),
- pipes.producer_handle.write_data(data))
- (res, buf) = pipes.consumer_handle.begin_read_data()
+ pipes.producer_handle.WriteData(data))
+ (res, buf) = pipes.consumer_handle.BeginReadData()
self.assertEquals(system.RESULT_OK, res)
self.assertEquals(DATA_SIZE, len(buf.buffer))
self.assertEquals(data, buf.buffer)
- self.assertEquals(system.RESULT_OK, buf.end(DATA_SIZE))
+ self.assertEquals(system.RESULT_OK, buf.End(DATA_SIZE))
- def test_create_shared_buffer(self):
- self._test_handles_creation(system.create_shared_buffer(DATA_SIZE))
+ def testCreateSharedBuffer(self):
+ self._testHandlesCreation(system.CreateSharedBuffer(DATA_SIZE))
- def test_create_shared_buffer_with_none_options(self):
- self._test_handles_creation(system.create_shared_buffer(DATA_SIZE, None))
+ def testCreateSharedBufferWithNoneOptions(self):
+ self._testHandlesCreation(system.CreateSharedBuffer(DATA_SIZE, None))
- def test_create_shared_buffer_with_default_options(self):
- self._test_handles_creation(
- system.create_shared_buffer(
+ def testCreateSharedBufferWithDefaultOptions(self):
+ self._testHandlesCreation(
+ system.CreateSharedBuffer(
DATA_SIZE,
system.CreateSharedBufferOptions()))
- def test_duplicate_shared_buffer(self):
- handle = system.create_shared_buffer(DATA_SIZE)
- self._test_handles_creation(handle.duplicate())
-
- def test_duplicate_shared_buffer_with_none_options(self):
- handle = system.create_shared_buffer(DATA_SIZE)
- self._test_handles_creation(handle.duplicate(None))
-
- def test_duplicate_shared_buffer_with_default_options(self):
- handle = system.create_shared_buffer(DATA_SIZE)
- self._test_handles_creation(
- handle.duplicate(system.DuplicateSharedBufferOptions()))
-
- def test_send_bytes_over_shared_buffer(self):
- handle = system.create_shared_buffer(DATA_SIZE)
- duplicated = handle.duplicate()
- data = get_random_buffer(DATA_SIZE)
- (res1, buf1) = handle.map(0, DATA_SIZE)
- (res2, buf2) = duplicated.map(0, DATA_SIZE)
+ def testDuplicateSharedBuffer(self):
+ handle = system.CreateSharedBuffer(DATA_SIZE)
+ self._testHandlesCreation(handle.Duplicate())
+
+ def testDuplicateSharedBufferWithNoneOptions(self):
+ handle = system.CreateSharedBuffer(DATA_SIZE)
+ self._testHandlesCreation(handle.Duplicate(None))
+
+ def testDuplicateSharedBufferWithDefaultOptions(self):
+ handle = system.CreateSharedBuffer(DATA_SIZE)
+ self._testHandlesCreation(
+ handle.Duplicate(system.DuplicateSharedBufferOptions()))
+
+ def testSendBytesOverSharedBuffer(self):
+ handle = system.CreateSharedBuffer(DATA_SIZE)
+ duplicated = handle.Duplicate()
+ data = _GetRandomBuffer(DATA_SIZE)
+ (res1, buf1) = handle.Map(0, DATA_SIZE)
+ (res2, buf2) = duplicated.Map(0, DATA_SIZE)
self.assertEquals(system.RESULT_OK, res1)
self.assertEquals(system.RESULT_OK, res2)
self.assertEquals(DATA_SIZE, len(buf1.buffer))
« no previous file with comments | « mojo/python/system/mojo/embedder.pyx ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698