releasetools: Move MockScriptWriter into test_utils.
Bug: 134525174 Test: TreeHugger Test: lunch a target; atest --host releasetools_test releasetools_py3_test Change-Id: I6d30f4d153d59d65227275e1d3285e30dfafd90e
This commit is contained in:
@@ -1232,24 +1232,6 @@ class InstallRecoveryScriptFormatTest(test_utils.ReleaseToolsTestCase):
|
|||||||
self._info)
|
self._info)
|
||||||
|
|
||||||
|
|
||||||
class MockScriptWriter(object):
|
|
||||||
"""A class that mocks edify_generator.EdifyGenerator."""
|
|
||||||
|
|
||||||
def __init__(self, enable_comments=False):
|
|
||||||
self.lines = []
|
|
||||||
self.enable_comments = enable_comments
|
|
||||||
|
|
||||||
def Comment(self, comment):
|
|
||||||
if self.enable_comments:
|
|
||||||
self.lines.append('# {}'.format(comment))
|
|
||||||
|
|
||||||
def AppendExtra(self, extra):
|
|
||||||
self.lines.append(extra)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return '\n'.join(self.lines)
|
|
||||||
|
|
||||||
|
|
||||||
class MockBlockDifference(object):
|
class MockBlockDifference(object):
|
||||||
|
|
||||||
def __init__(self, partition, tgt, src=None):
|
def __init__(self, partition, tgt, src=None):
|
||||||
@@ -1287,7 +1269,7 @@ class DynamicPartitionsDifferenceTest(test_utils.ReleaseToolsTestCase):
|
|||||||
if not line.startswith(b'#')]
|
if not line.startswith(b'#')]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.script = MockScriptWriter()
|
self.script = test_utils.MockScriptWriter()
|
||||||
self.output_path = common.MakeTempFile(suffix='.zip')
|
self.output_path = common.MakeTempFile(suffix='.zip')
|
||||||
|
|
||||||
def test_full(self):
|
def test_full(self):
|
||||||
|
@@ -74,35 +74,6 @@ def construct_target_files(secondary=False):
|
|||||||
return target_files
|
return target_files
|
||||||
|
|
||||||
|
|
||||||
class MockScriptWriter(object):
|
|
||||||
"""A class that mocks edify_generator.EdifyGenerator.
|
|
||||||
|
|
||||||
It simply pushes the incoming arguments onto script stack, which is to assert
|
|
||||||
the calls to EdifyGenerator functions.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.script = []
|
|
||||||
|
|
||||||
def Mount(self, *args):
|
|
||||||
self.script.append(('Mount',) + args)
|
|
||||||
|
|
||||||
def AssertDevice(self, *args):
|
|
||||||
self.script.append(('AssertDevice',) + args)
|
|
||||||
|
|
||||||
def AssertOemProperty(self, *args):
|
|
||||||
self.script.append(('AssertOemProperty',) + args)
|
|
||||||
|
|
||||||
def AssertFingerprintOrThumbprint(self, *args):
|
|
||||||
self.script.append(('AssertFingerprintOrThumbprint',) + args)
|
|
||||||
|
|
||||||
def AssertSomeFingerprint(self, *args):
|
|
||||||
self.script.append(('AssertSomeFingerprint',) + args)
|
|
||||||
|
|
||||||
def AssertSomeThumbprint(self, *args):
|
|
||||||
self.script.append(('AssertSomeThumbprint',) + args)
|
|
||||||
|
|
||||||
|
|
||||||
class BuildInfoTest(test_utils.ReleaseToolsTestCase):
|
class BuildInfoTest(test_utils.ReleaseToolsTestCase):
|
||||||
|
|
||||||
TEST_INFO_DICT = {
|
TEST_INFO_DICT = {
|
||||||
@@ -281,20 +252,20 @@ class BuildInfoTest(test_utils.ReleaseToolsTestCase):
|
|||||||
def test_WriteMountOemScript(self):
|
def test_WriteMountOemScript(self):
|
||||||
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
||||||
self.TEST_OEM_DICTS)
|
self.TEST_OEM_DICTS)
|
||||||
script_writer = MockScriptWriter()
|
script_writer = test_utils.MockScriptWriter()
|
||||||
target_info.WriteMountOemScript(script_writer)
|
target_info.WriteMountOemScript(script_writer)
|
||||||
self.assertEqual([('Mount', '/oem', None)], script_writer.script)
|
self.assertEqual([('Mount', '/oem', None)], script_writer.lines)
|
||||||
|
|
||||||
def test_WriteDeviceAssertions(self):
|
def test_WriteDeviceAssertions(self):
|
||||||
target_info = BuildInfo(self.TEST_INFO_DICT, None)
|
target_info = BuildInfo(self.TEST_INFO_DICT, None)
|
||||||
script_writer = MockScriptWriter()
|
script_writer = test_utils.MockScriptWriter()
|
||||||
target_info.WriteDeviceAssertions(script_writer, False)
|
target_info.WriteDeviceAssertions(script_writer, False)
|
||||||
self.assertEqual([('AssertDevice', 'product-device')], script_writer.script)
|
self.assertEqual([('AssertDevice', 'product-device')], script_writer.lines)
|
||||||
|
|
||||||
def test_WriteDeviceAssertions_with_oem_props(self):
|
def test_WriteDeviceAssertions_with_oem_props(self):
|
||||||
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
||||||
self.TEST_OEM_DICTS)
|
self.TEST_OEM_DICTS)
|
||||||
script_writer = MockScriptWriter()
|
script_writer = test_utils.MockScriptWriter()
|
||||||
target_info.WriteDeviceAssertions(script_writer, False)
|
target_info.WriteDeviceAssertions(script_writer, False)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[
|
[
|
||||||
@@ -303,7 +274,7 @@ class BuildInfoTest(test_utils.ReleaseToolsTestCase):
|
|||||||
('AssertOemProperty', 'ro.product.brand',
|
('AssertOemProperty', 'ro.product.brand',
|
||||||
['brand1', 'brand2', 'brand3'], False),
|
['brand1', 'brand2', 'brand3'], False),
|
||||||
],
|
],
|
||||||
script_writer.script)
|
script_writer.lines)
|
||||||
|
|
||||||
def test_WriteFingerprintAssertion_without_oem_props(self):
|
def test_WriteFingerprintAssertion_without_oem_props(self):
|
||||||
target_info = BuildInfo(self.TEST_INFO_DICT, None)
|
target_info = BuildInfo(self.TEST_INFO_DICT, None)
|
||||||
@@ -312,36 +283,36 @@ class BuildInfoTest(test_utils.ReleaseToolsTestCase):
|
|||||||
'source-build-fingerprint')
|
'source-build-fingerprint')
|
||||||
source_info = BuildInfo(source_info_dict, None)
|
source_info = BuildInfo(source_info_dict, None)
|
||||||
|
|
||||||
script_writer = MockScriptWriter()
|
script_writer = test_utils.MockScriptWriter()
|
||||||
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[('AssertSomeFingerprint', 'source-build-fingerprint',
|
[('AssertSomeFingerprint', 'source-build-fingerprint',
|
||||||
'build-fingerprint')],
|
'build-fingerprint')],
|
||||||
script_writer.script)
|
script_writer.lines)
|
||||||
|
|
||||||
def test_WriteFingerprintAssertion_with_source_oem_props(self):
|
def test_WriteFingerprintAssertion_with_source_oem_props(self):
|
||||||
target_info = BuildInfo(self.TEST_INFO_DICT, None)
|
target_info = BuildInfo(self.TEST_INFO_DICT, None)
|
||||||
source_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
source_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
||||||
self.TEST_OEM_DICTS)
|
self.TEST_OEM_DICTS)
|
||||||
|
|
||||||
script_writer = MockScriptWriter()
|
script_writer = test_utils.MockScriptWriter()
|
||||||
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[('AssertFingerprintOrThumbprint', 'build-fingerprint',
|
[('AssertFingerprintOrThumbprint', 'build-fingerprint',
|
||||||
'build-thumbprint')],
|
'build-thumbprint')],
|
||||||
script_writer.script)
|
script_writer.lines)
|
||||||
|
|
||||||
def test_WriteFingerprintAssertion_with_target_oem_props(self):
|
def test_WriteFingerprintAssertion_with_target_oem_props(self):
|
||||||
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
||||||
self.TEST_OEM_DICTS)
|
self.TEST_OEM_DICTS)
|
||||||
source_info = BuildInfo(self.TEST_INFO_DICT, None)
|
source_info = BuildInfo(self.TEST_INFO_DICT, None)
|
||||||
|
|
||||||
script_writer = MockScriptWriter()
|
script_writer = test_utils.MockScriptWriter()
|
||||||
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[('AssertFingerprintOrThumbprint', 'build-fingerprint',
|
[('AssertFingerprintOrThumbprint', 'build-fingerprint',
|
||||||
'build-thumbprint')],
|
'build-thumbprint')],
|
||||||
script_writer.script)
|
script_writer.lines)
|
||||||
|
|
||||||
def test_WriteFingerprintAssertion_with_both_oem_props(self):
|
def test_WriteFingerprintAssertion_with_both_oem_props(self):
|
||||||
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
target_info = BuildInfo(self.TEST_INFO_DICT_USES_OEM_PROPS,
|
||||||
@@ -351,12 +322,12 @@ class BuildInfoTest(test_utils.ReleaseToolsTestCase):
|
|||||||
'source-build-thumbprint')
|
'source-build-thumbprint')
|
||||||
source_info = BuildInfo(source_info_dict, self.TEST_OEM_DICTS)
|
source_info = BuildInfo(source_info_dict, self.TEST_OEM_DICTS)
|
||||||
|
|
||||||
script_writer = MockScriptWriter()
|
script_writer = test_utils.MockScriptWriter()
|
||||||
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
WriteFingerprintAssertion(script_writer, target_info, source_info)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
[('AssertSomeThumbprint', 'build-thumbprint',
|
[('AssertSomeThumbprint', 'build-thumbprint',
|
||||||
'source-build-thumbprint')],
|
'source-build-thumbprint')],
|
||||||
script_writer.script)
|
script_writer.lines)
|
||||||
|
|
||||||
|
|
||||||
class LoadOemDictsTest(test_utils.ReleaseToolsTestCase):
|
class LoadOemDictsTest(test_utils.ReleaseToolsTestCase):
|
||||||
|
@@ -145,6 +145,47 @@ def construct_sparse_image(chunks):
|
|||||||
return sparse_image
|
return sparse_image
|
||||||
|
|
||||||
|
|
||||||
|
class MockScriptWriter(object):
|
||||||
|
"""A class that mocks edify_generator.EdifyGenerator.
|
||||||
|
|
||||||
|
It simply pushes the incoming arguments onto script stack, which is to assert
|
||||||
|
the calls to EdifyGenerator functions.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, enable_comments=False):
|
||||||
|
self.lines = []
|
||||||
|
self.enable_comments = enable_comments
|
||||||
|
|
||||||
|
def Mount(self, *args):
|
||||||
|
self.lines.append(('Mount',) + args)
|
||||||
|
|
||||||
|
def AssertDevice(self, *args):
|
||||||
|
self.lines.append(('AssertDevice',) + args)
|
||||||
|
|
||||||
|
def AssertOemProperty(self, *args):
|
||||||
|
self.lines.append(('AssertOemProperty',) + args)
|
||||||
|
|
||||||
|
def AssertFingerprintOrThumbprint(self, *args):
|
||||||
|
self.lines.append(('AssertFingerprintOrThumbprint',) + args)
|
||||||
|
|
||||||
|
def AssertSomeFingerprint(self, *args):
|
||||||
|
self.lines.append(('AssertSomeFingerprint',) + args)
|
||||||
|
|
||||||
|
def AssertSomeThumbprint(self, *args):
|
||||||
|
self.lines.append(('AssertSomeThumbprint',) + args)
|
||||||
|
|
||||||
|
def Comment(self, comment):
|
||||||
|
if not self.enable_comments:
|
||||||
|
return
|
||||||
|
self.lines.append('# {}'.format(comment))
|
||||||
|
|
||||||
|
def AppendExtra(self, extra):
|
||||||
|
self.lines.append(extra)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '\n'.join(self.lines)
|
||||||
|
|
||||||
|
|
||||||
class ReleaseToolsTestCase(unittest.TestCase):
|
class ReleaseToolsTestCase(unittest.TestCase):
|
||||||
"""A common base class for all the releasetools unittests."""
|
"""A common base class for all the releasetools unittests."""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user