Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7436a712 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Updates test_config_fixer to also work for SuiteApkInstaller"

parents b2d87ef0 48a8f0d1
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ from manifest import parse_manifest
from manifest import parse_test_config
from manifest import write_xml

KNOWN_PREPARERS = ['com.android.tradefed.targetprep.TestAppInstallSetup',
                   'com.android.tradefed.targetprep.suite.SuiteApkInstaller']

def parse_args():
  """Parse commandline arguments."""
@@ -64,7 +66,7 @@ def overwrite_test_file_name(test_config_doc, test_file_name):
  tests = get_children_with_tag(test_config, 'target_preparer')

  for test in tests:
    if test.getAttribute('class') == "com.android.tradefed.targetprep.TestAppInstallSetup":
    if test.getAttribute('class') in KNOWN_PREPARERS:
      options = get_children_with_tag(test, 'option')
      for option in options:
        if option.getAttribute('name') == "test-file-name":
+27 −4
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ class OverwritePackageNameTest(unittest.TestCase):
class OverwriteTestFileNameTest(unittest.TestCase):
  """ Unit tests for overwrite_test_file_name function """

  test_config = (
  test_config_test_app_install_setup = (
      '<?xml version="1.0" encoding="utf-8"?>\n'
      '<configuration description="Runs some tests.">\n'
      '    <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">\n'
@@ -82,15 +82,38 @@ class OverwriteTestFileNameTest(unittest.TestCase):
      '    </test>\n'
      '</configuration>\n')

  def test_all(self):
    doc = minidom.parseString(self.test_config % ("foo.apk"))
  test_config_suite_apk_installer = (
      '<?xml version="1.0" encoding="utf-8"?>\n'
      '<configuration description="Runs some tests.">\n'
      '    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">\n'
      '        <option name="test-file-name" value="%s"/>\n'
      '    </target_preparer>\n'
      '    <test class="com.android.tradefed.testtype.AndroidJUnitTest">\n'
      '        <option name="package" value="com.android.foo"/>\n'
      '        <option name="runtime-hint" value="20s"/>\n'
      '    </test>\n'
      '</configuration>\n')

  def test_testappinstallsetup(self):
    doc = minidom.parseString(self.test_config_test_app_install_setup % ("foo.apk"))

    test_config_fixer.overwrite_test_file_name(doc, "bar.apk")
    output = io.StringIO()
    test_config_fixer.write_xml(output, doc)

    # Only the matching package name in a test node should be updated.
    expected = self.test_config_test_app_install_setup % ("bar.apk")
    self.assertEqual(expected, output.getvalue())

  def test_suiteapkinstaller(self):
    doc = minidom.parseString(self.test_config_suite_apk_installer % ("foo.apk"))

    test_config_fixer.overwrite_test_file_name(doc, "bar.apk")
    output = io.StringIO()
    test_config_fixer.write_xml(output, doc)

    # Only the matching package name in a test node should be updated.
    expected = self.test_config % ("bar.apk")
    expected = self.test_config_suite_apk_installer % ("bar.apk")
    self.assertEqual(expected, output.getvalue())