提交 502c8c5c 编写于 作者: W Wainer dos Santos Moschetta 提交者: Cleber Rosa

Refactor whiteboard example test

Moved original whiteboard example test to selftests and then
created a simpler example code.

Reference: https://trello.com/c/sG6J0VpwSigned-off-by: NWainer dos Santos Moschetta <wainersm@redhat.com>
上级 0b9b4ca2
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
import base64 import base64
from six.moves import xrange as range
from avocado import Test from avocado import Test
from avocado import main from avocado import main
...@@ -11,34 +9,14 @@ from avocado import main ...@@ -11,34 +9,14 @@ from avocado import main
class WhiteBoard(Test): class WhiteBoard(Test):
""" """
Simple test that saves test custom data to the test whiteboard Example of whiteboard usage.
:param whiteboard_data_file: File to be used as source for whiteboard data
:param whiteboard_data_size: Size of the generated data of the whiteboard
:param whiteboard_data_text: Text used when no file supplied
:param whiteboard_writes: How many times to copy the data into whiteboard
""" """
def test(self): def test(self):
data_file = self.params.get('whiteboard_data_file', default='') """
data_size = self.params.get('whiteboard_data_size', default='10') This should write a message to the whiteboard.
if data_file: """
self.log.info('Writing data to whiteboard from file: %s', self.whiteboard = base64.encodestring(b'My message encoded in base64').decode('ascii')
data_file)
with open(data_file, 'r') as whiteboard_file:
size = int(data_size)
data = whiteboard_file.read(size)
else:
offset = int(data_size) - 1
data = self.params.get('whiteboard_data_text',
default='default whiteboard text')[0:offset]
iterations = int(self.params.get('whiteboard_writes', default=1))
result = ''
for _ in range(0, iterations):
result += data
self.whiteboard = base64.encodestring(result.encode()).decode('ascii')
if __name__ == "__main__": if __name__ == "__main__":
......
source: !mux
string:
whiteboard_data_text: 'foo bar foo baz'
urandom:
whiteboard_data_file: '/dev/urandom'
iterations: !mux
single:
whiteboard_writes: 1
dozen:
whiteboard_writes: 12
size: !mux
onekilo:
whiteboard_data_size: 1024
onemega:
whiteboard_data_size: 1048576
#!/usr/bin/env python
import base64
from six.moves import xrange as range
from avocado import Test
from avocado import main
class WhiteBoard(Test):
"""
Simple test that saves test custom data to the test whiteboard
:param whiteboard_data_file: File to be used as source for whiteboard data
:param whiteboard_data_size: Size of the generated data of the whiteboard
:param whiteboard_data_text: Text used when no file supplied
:param whiteboard_writes: How many times to copy the data into whiteboard
"""
def test(self):
data_file = self.params.get('whiteboard_data_file', default='')
data_size = self.params.get('whiteboard_data_size', default='10')
if data_file:
self.log.info('Writing data to whiteboard from file: %s',
data_file)
with open(data_file, 'r') as whiteboard_file:
size = int(data_size)
data = whiteboard_file.read(size)
else:
offset = int(data_size) - 1
data = self.params.get('whiteboard_data_text',
default='default whiteboard text')[0:offset]
iterations = int(self.params.get('whiteboard_writes', default=1))
result = ''
for _ in range(0, iterations):
result += data
self.whiteboard = base64.encodestring(result.encode()).decode('ascii')
if __name__ == "__main__":
main()
...@@ -55,7 +55,7 @@ class TestRunnerQueue(unittest.TestCase): ...@@ -55,7 +55,7 @@ class TestRunnerQueue(unittest.TestCase):
'base_logdir': self.tmpdir}] 'base_logdir': self.tmpdir}]
msg = self._run_test(factory) msg = self._run_test(factory)
self.assertEqual(msg['whiteboard'], 'ZGVmYXVsdCB3\n') self.assertEqual(msg['whiteboard'], 'TXkgbWVzc2FnZSBlbmNvZGVkIGluIGJhc2U2NA==\n')
def tearDown(self): def tearDown(self):
shutil.rmtree(self.tmpdir) shutil.rmtree(self.tmpdir)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册