Ejemplo n.º 1
0
 def test_caching_multiple_sdks(self):
     with distribution() as first_sdk_path:
         with distribution() as second_sdk_path:
             first_sdk_instance = AndroidDistribution.cached(first_sdk_path)
             second_sdk_instance = AndroidDistribution.cached(second_sdk_path)
             self.assertEquals(AndroidDistribution._CACHED_SDK[first_sdk_path], first_sdk_instance)
             self.assertEquals(AndroidDistribution._CACHED_SDK[second_sdk_path], second_sdk_instance)
 def test_caching_multiple_sdks(self):
     with distribution() as first_sdk_path:
         with distribution() as second_sdk_path:
             first_sdk_instance = AndroidDistribution.cached(first_sdk_path)
             second_sdk_instance = AndroidDistribution.cached(
                 second_sdk_path)
             self.assertEquals(
                 AndroidDistribution._CACHED_SDK[first_sdk_path],
                 first_sdk_instance)
             self.assertEquals(
                 AndroidDistribution._CACHED_SDK[second_sdk_path],
                 second_sdk_instance)
Ejemplo n.º 3
0
 def test_register_copy_but_no_tool(self):
     with distribution() as sdk:
         with temporary_dir() as workdir:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join("platforms", "android-19", "no.jar")
             with self.assertRaises(AndroidDistribution.DistributionError):
                 android_sdk.register_android_tool(android_jar, workdir=workdir)
Ejemplo n.º 4
0
 def test_get_bad_tool_path(self):
     with self.assertRaises(AndroidDistribution.DistributionError):
         with distribution() as sdk:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join("platforms", "android-19", "no.jar")
             tool_path = android_sdk._get_tool_path(android_jar)
             self.assertEquals(tool_path, os.path.join(sdk, android_jar))
Ejemplo n.º 5
0
 def test_register_tool_returns_file(self):
     with distribution() as sdk:
         with temporary_dir() as workdir:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join("platforms", "android-19", "android.jar")
             android_sdk.register_android_tool(android_jar, workdir=workdir)
             self.assertEquals(os.path.isfile(android_sdk._validated_tools[android_jar]), True)
Ejemplo n.º 6
0
 def test_force_build_tools_version_dx_jar_tool(self):
   with distribution() as dist:
     with self.android_binary() as android_binary:
       self.set_options(sdk_path=dist, build_tools_version='20.0.0')
       task = self.create_task(self.context())
       dx_jar = os.path.join(dist, 'build-tools', '20.0.0', 'lib/dx.jar')
       self.assertEqual(task.dx_jar_tool(android_binary.build_tools_version), dx_jar)
Ejemplo n.º 7
0
 def test_force_build_tools_version_dx_jar_tool(self):
   with distribution() as dist:
     with self.android_binary() as android_binary:
       self.set_options(sdk_path=dist, build_tools_version='20.0.0')
       task = self.create_task(self.context())
       dx_jar = os.path.join(dist, 'build-tools', '20.0.0', 'lib/dx.jar')
       self.assertEqual(task.dx_jar_tool(android_binary.build_tools_version), dx_jar)
 def test_get_bad_tool_path(self):
     with self.assertRaises(AndroidDistribution.DistributionError):
         with distribution() as sdk:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join('platforms', 'android-19', 'no.jar')
             tool_path = android_sdk._get_tool_path(android_jar)
             self.assertEquals(tool_path, os.path.join(sdk, android_jar))
Ejemplo n.º 9
0
 def test_register_copy_is_validated(self):
     with distribution() as sdk:
         with temporary_dir() as workdir:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join("platforms", "android-19", "android.jar")
             android_sdk.register_android_tool(android_jar, workdir=workdir)
             self.assertIn(android_jar, android_sdk._validated_tools)
Ejemplo n.º 10
0
 def test_zipalign_out(self):
   with distribution() as dist:
     with self.android_binary() as android_binary:
       self.set_options(sdk_path=dist)
       task = self.create_task(self.context())
       target = android_binary
       self.assertEqual(task.zipalign_out(target), os.path.join(task._distdir, target.name))
 def test_register_copy_is_validated(self):
     with distribution() as sdk:
         with temporary_dir() as workdir:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join('platforms', 'android-19',
                                        'android.jar')
             android_sdk.register_android_tool(android_jar, workdir=workdir)
             self.assertIn(android_jar, android_sdk._validated_tools)
Ejemplo n.º 12
0
 def test_register_tool_no_permission(self):
     with self.assertRaises(AndroidDistribution.DistributionError):
         with distribution() as sdk:
             with temporary_dir() as workdir:
                 os.chmod(workdir, 0o400)
                 android_sdk = AndroidDistribution.cached(sdk)
                 android_jar = os.path.join("platforms", "android-19", "android.jar")
                 android_sdk.register_android_tool(android_jar, workdir=workdir)
Ejemplo n.º 13
0
 def test_render_args(self):
   with distribution() as dist:
     with self.android_binary() as android_binary:
       self.set_options(sdk_path=dist)
       task = self.create_task(self.context())
       rendered_args = task._render_args(android_binary, 'res', ['classes.dex'])
       self.assertEquals(os.path.basename(rendered_args[0]), 'aapt')
       self.assertEquals(rendered_args[-1], 'classes.dex')
Ejemplo n.º 14
0
 def test_aapt_tool(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist, build_tools_version="20.0.0")
             task = self.create_task(self.context())
             aapt_tool = task.aapt_tool(android_binary)
             self.assertEquals(os.path.basename(os.path.dirname(aapt_tool)), "20.0.0")
             self.assertEquals(os.path.basename(aapt_tool), "aapt")
Ejemplo n.º 15
0
 def test_android_tool(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist, target_sdk="18")
             task = self.create_task(self.context())
             android_jar = task.android_jar(android_binary)
             self.assertEquals(os.path.basename(os.path.dirname(android_jar)), "android-18")
             self.assertEquals(os.path.basename(android_jar), "android.jar")
Ejemplo n.º 16
0
 def test_render_args(self):
     with distribution() as dist:
         with self.android_resources() as resources:
             with self.android_binary(dependencies=[resources]) as binary:
                 self.set_options(sdk_path=dist)
                 task = self.create_task(self.context())
                 rendered_args = task._render_args(binary, binary.manifest, [resources.resource_dir])
             self.assertEquals(os.path.basename(rendered_args[0]), "aapt")
Ejemplo n.º 17
0
 def test_zipalign_out(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist)
             task = self.create_task(self.context())
             target = android_binary
             self.assertEqual(task.zipalign_out(target),
                              os.path.join(task._distdir, target.name))
Ejemplo n.º 18
0
 def test_zipalign_binary(self):
   with distribution() as dist:
     with self.android_binary() as android_binary:
       self.set_options(sdk_path=dist)
       task = self.create_task(self.context())
       target = android_binary
       self.assertEqual(task.zipalign_binary(target),
                        os.path.join(dist, 'build-tools', target.build_tools_version, 'zipalign'))
Ejemplo n.º 19
0
 def test_register_copy_but_no_tool(self):
     with distribution() as sdk:
         with temporary_dir() as workdir:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join('platforms', 'android-19', 'no.jar')
             with self.assertRaises(AndroidDistribution.DistributionError):
                 android_sdk.register_android_tool(android_jar,
                                                   workdir=workdir)
Ejemplo n.º 20
0
 def test_render_args(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist)
             task = self.create_task(self.context())
             rendered_args = task._render_args(android_binary, 'res',
                                               ['classes.dex'])
             self.assertEquals(os.path.basename(rendered_args[0]), 'aapt')
             self.assertEquals(rendered_args[-1], 'classes.dex')
Ejemplo n.º 21
0
 def test_aapt_tool(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist, build_tools_version='20.0.0')
             task = self.create_task(self.context())
             aapt_tool = task.aapt_tool(android_binary)
             self.assertEquals(os.path.basename(os.path.dirname(aapt_tool)),
                               '20.0.0')
             self.assertEquals(os.path.basename(aapt_tool), 'aapt')
Ejemplo n.º 22
0
 def test_create_sdk_jar_deps(self):
     with distribution() as dist:
         with self.android_binary(target_name="binary1", target_sdk="18") as binary1:
             with self.android_binary(target_name="binary2", target_sdk="19") as binary2:
                 self.set_options(sdk_path=dist)
                 task = self.create_task(self.context())
                 targets = [binary1, binary2]
                 task.create_sdk_jar_deps(targets)
                 self.assertNotEquals(task._jar_library_by_sdk["19"], task._jar_library_by_sdk["18"])
Ejemplo n.º 23
0
 def test_render_args_force_ignored(self):
     with distribution() as dist:
         with self.android_resources() as resources:
             with self.android_binary(dependencies=[resources]) as binary:
                 ignored = "!picasa.ini:!*~:BUILD*"
                 self.set_options(sdk_path=dist, ignored_assets=ignored)
                 task = self.create_task(self.context())
                 rendered_args = task._render_args(binary, binary.manifest, [resources.resource_dir])
                 self.assertIn(ignored, rendered_args)
Ejemplo n.º 24
0
 def test_render_args(self):
     with distribution() as dist:
         with self.android_resources() as resources:
             with self.android_binary(dependencies=[resources]) as binary:
                 self.set_options(sdk_path=dist)
                 task = self.create_task(self.context())
                 rendered_args = task._render_args(binary, binary.manifest,
                                                   [resources.resource_dir])
             self.assertEquals(os.path.basename(rendered_args[0]), 'aapt')
 def test_register_tool_returns_file(self):
     with distribution() as sdk:
         with temporary_dir() as workdir:
             android_sdk = AndroidDistribution.cached(sdk)
             android_jar = os.path.join('platforms', 'android-19',
                                        'android.jar')
             android_sdk.register_android_tool(android_jar, workdir=workdir)
             self.assertEquals(
                 os.path.isfile(android_sdk._validated_tools[android_jar]),
                 True)
Ejemplo n.º 26
0
 def test_android_tool(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist, target_sdk='18')
             task = self.create_task(self.context())
             android_jar = task.android_jar(android_binary)
             self.assertEquals(
                 os.path.basename(os.path.dirname(android_jar)),
                 'android-18')
             self.assertEquals(os.path.basename(android_jar), 'android.jar')
Ejemplo n.º 27
0
 def test_zipalign_binary(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist)
             task = self.create_task(self.context())
             target = android_binary
             self.assertEqual(
                 task.zipalign_binary(target),
                 os.path.join(dist, 'build-tools',
                              target.build_tools_version, 'zipalign'))
Ejemplo n.º 28
0
 def test_render_args_force_ignored(self):
     with distribution() as dist:
         with self.android_resources() as resources:
             with self.android_binary(dependencies=[resources]) as binary:
                 ignored = '!picasa.ini:!*~:BUILD*'
                 self.set_options(sdk_path=dist, ignored_assets=ignored)
                 task = self.create_task(self.context())
                 rendered_args = task._render_args(binary, binary.manifest,
                                                   [resources.resource_dir])
                 self.assertIn(ignored, rendered_args)
 def test_register_tool_no_permission(self):
     with self.assertRaises(AndroidDistribution.DistributionError):
         with distribution() as sdk:
             with temporary_dir() as workdir:
                 os.chmod(workdir, 0o400)
                 android_sdk = AndroidDistribution.cached(sdk)
                 android_jar = os.path.join('platforms', 'android-19',
                                            'android.jar')
                 android_sdk.register_android_tool(android_jar,
                                                   workdir=workdir)
Ejemplo n.º 30
0
 def test_create_target(self):
     with distribution() as dist:
         with self.android_library() as library:
             with self.android_binary(dependencies=[library]) as android_binary:
                 self.set_options(sdk_path=dist)
                 task = self.create_task(self.context())
                 targets = [android_binary]
                 task.create_sdk_jar_deps(targets)
                 created_target = task.create_target(android_binary, library)
                 self.assertEqual(created_target.derived_from, library)
                 self.assertTrue(created_target.is_synthetic)
Ejemplo n.º 31
0
 def test_render_args(self):
   with distribution() as dist:
     with self.android_binary() as android_binary:
       self.set_options(sdk_path=dist)
       task = self.create_task(self.context())
       target = android_binary
       expected_args = [os.path.join(dist, 'build-tools', target.build_tools_version, 'zipalign'),
                        '-f', '4', 'package/path',
                        os.path.join(task._distdir, target.name,
                                     '{0}.signed.apk'.format(target.name))]
       self.assertEqual(task._render_args('package/path', target), expected_args)
Ejemplo n.º 32
0
 def test_create_sdk_jar_deps(self):
     with distribution() as dist:
         with self.android_binary(target_name='binary1',
                                  target_sdk='18') as binary1:
             with self.android_binary(target_name='binary2',
                                      target_sdk='19') as binary2:
                 self.set_options(sdk_path=dist)
                 task = self.create_task(self.context())
                 targets = [binary1, binary2]
                 task.create_sdk_jar_deps(targets)
                 self.assertNotEquals(task._jar_library_by_sdk['19'],
                                      task._jar_library_by_sdk['18'])
Ejemplo n.º 33
0
 def test_create_target(self):
     with distribution() as dist:
         with self.android_library() as library:
             with self.android_binary(
                     dependencies=[library]) as android_binary:
                 self.set_options(sdk_path=dist)
                 task = self.create_task(self.context())
                 targets = [android_binary]
                 task.create_sdk_jar_deps(targets)
                 created_target = task.create_target(
                     android_binary, library)
                 self.assertEqual(created_target.derived_from, library)
                 self.assertTrue(created_target.is_synthetic)
Ejemplo n.º 34
0
  def test_resource_order_in_args(self):
    with distribution() as dist:
      with self.android_resources(target_name='binary_resources') as res1:
        with self.android_resources(target_name='library_resources') as res2:
          with self.android_library(dependencies=[res2]) as library:
            with self.android_binary(dependencies=[res1, library]) as target:
              self.set_options(sdk_path=dist)
              task = self.create_task(self.context())

              res_dirs = [res1.resource_dir, res2.resource_dir]
              rendered_args = task._render_args(target, res_dirs, 'classes.dex')

              args_string = ' '.join(rendered_args)
              self.assertIn('--auto-add-overlay -S {} -S '
                            '{}'.format(res1.resource_dir, res2.resource_dir), args_string)
Ejemplo n.º 35
0
 def test_render_args(self):
     with distribution() as dist:
         with self.android_binary() as android_binary:
             self.set_options(sdk_path=dist)
             task = self.create_task(self.context())
             target = android_binary
             expected_args = [
                 os.path.join(dist, 'build-tools',
                              target.build_tools_version, 'zipalign'), '-f',
                 '4', 'package/path',
                 os.path.join(
                     task._distdir, target.name,
                     '{0}.signed.apk'.format(target.manifest.package_name))
             ]
             self.assertEqual(task._render_args('package/path', target),
                              expected_args)
Ejemplo n.º 36
0
    def test_priority_order_in_render_args(self):
        with distribution() as dist:
            with self.android_resources(target_name="binary_resources") as res1:
                with self.android_resources(target_name="library_resources") as res2:
                    with self.android_library(dependencies=[res2]) as library:
                        with self.android_binary(dependencies=[res1, library]) as binary:
                            self.set_options(sdk_path=dist)
                            task = self.create_task(self.context())

                            res_dirs = [res1.resource_dir, res2.resource_dir]
                            rendered_args = task._render_args(binary, binary.manifest, res_dirs)
                            args_string = " ".join(rendered_args)
                            self.assertIn(
                                "--auto-add-overlay -S {} -S " "{}".format(res1.resource_dir, res2.resource_dir),
                                args_string,
                            )
Ejemplo n.º 37
0
    def test_priority_order_in_render_args(self):
        with distribution() as dist:
            with self.android_resources(
                    target_name='binary_resources') as res1:
                with self.android_resources(
                        target_name='library_resources') as res2:
                    with self.android_library(dependencies=[res2]) as library:
                        with self.android_binary(
                                dependencies=[res1, library]) as binary:
                            self.set_options(sdk_path=dist)
                            task = self.create_task(self.context())

                            res_dirs = [res1.resource_dir, res2.resource_dir]
                            rendered_args = task._render_args(
                                binary, binary.manifest, res_dirs)
                            args_string = ' '.join(rendered_args)
                            self.assertIn(
                                '--auto-add-overlay -S {} -S '
                                '{}'.format(res1.resource_dir,
                                            res2.resource_dir), args_string)
Ejemplo n.º 38
0
 def test_passing_sdk_path(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution(sdk_path=sdk)
         aapt = os.path.join(sdk, "build-tools", "19.1.0", "aapt")
         android_tool = android_sdk.register_android_tool(aapt)
         self.assertEquals(android_tool, os.path.join(sdk, aapt))
 def test_passing_sdk_path_missing_tools(self):
     with self.assertRaises(AndroidDistribution.DistributionError):
         with distribution() as sdk:
             aapt = os.path.join(sdk, 'build-tools', 'bad-number', 'aapt')
             AndroidDistribution(sdk_path=sdk).register_android_tool(aapt)
 def test_locate_no_sdk_on_path(self):
     with self.assertRaises(AndroidDistribution.DistributionError):
         with distribution() as sdk:
             with self.env(ANDROooooD_HOME=sdk):
                 dist = AndroidDistribution.locate_sdk_path()
                 self.assertEquals(dist._sdk_path, None)
Ejemplo n.º 41
0
 def test_validated_tools(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         aapt = os.path.join("build-tools", "19.1.0", "aapt")
         android_sdk.register_android_tool(aapt)
         self.assertIn(aapt, android_sdk._validated_tools)
Ejemplo n.º 42
0
 def test_locate_sdk_path(self):
     with distribution() as sdk:
         with self.env(ANDROID_HOME=sdk):
             dist = AndroidDistribution.locate_sdk_path()
             self.assertEquals(dist._sdk_path, sdk)
 def test_locate_sdk_path(self):
     with distribution() as sdk:
         with self.env(ANDROID_HOME=sdk):
             dist = AndroidDistribution.locate_sdk_path()
             self.assertEquals(dist._sdk_path, sdk)
 def test_locate_alternative_variables(self):
     # Test that alternative environmental variables are accepted.
     with distribution() as sdk:
         with self.env(ANDROID_SDK=sdk):
             dist = AndroidDistribution.locate_sdk_path()
             self.assertEquals(dist._sdk_path, sdk)
 def test_validated_tools(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         aapt = os.path.join('build-tools', '19.1.0', 'aapt')
         android_sdk.register_android_tool(aapt)
         self.assertIn(aapt, android_sdk._validated_tools)
 def test_register_nonexistent_android_tool(self):
     with self.assertRaises(AndroidDistribution.DistributionError):
         with distribution() as sdk:
             android_sdk = AndroidDistribution.cached(sdk)
             android_sdk.register_android_tool(
                 os.path.join('build-tools', '19.1.0', 'random_tool'))
 def test_passing_sdk_path(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution(sdk_path=sdk)
         aapt = os.path.join(sdk, 'build-tools', '19.1.0', 'aapt')
         android_tool = android_sdk.register_android_tool(aapt)
         self.assertEquals(android_tool, os.path.join(sdk, aapt))
 def test_register_android_tool(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         aapt = os.path.join('build-tools', '19.1.0', 'aapt')
         registered_aapt = android_sdk.register_android_tool(aapt)
         self.assertEquals(registered_aapt, os.path.join(sdk, aapt))
Ejemplo n.º 49
0
    def test_passing_sdk_path_missing_tools(self):
        with distribution() as sdk:
            aapt = os.path.join(sdk, "build-tools", "bad-number", "aapt")

            with self.assertRaises(AndroidDistribution.DistributionError):
                AndroidDistribution(sdk_path=sdk).register_android_tool(aapt)
Ejemplo n.º 50
0
 def test_locate_no_sdk_on_path(self):
     with distribution() as sdk:
         with self.env(ANDROooooD_HOME=sdk):
             with self.assertRaises(AndroidDistribution.DistributionError):
                 AndroidDistribution.locate_sdk_path()
Ejemplo n.º 51
0
 def test_register_android_tool(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         aapt = os.path.join("build-tools", "19.1.0", "aapt")
         registered_aapt = android_sdk.register_android_tool(aapt)
         self.assertEquals(registered_aapt, os.path.join(sdk, aapt))
Ejemplo n.º 52
0
 def test_locate_alternative_variables(self):
     # Test that alternative environmental variables are accepted.
     with distribution() as sdk:
         with self.env(ANDROID_SDK=sdk):
             dist = AndroidDistribution.locate_sdk_path()
             self.assertEquals(dist._sdk_path, sdk)
Ejemplo n.º 53
0
 def test_register_nonexistent_android_tool(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         with self.assertRaises(AndroidDistribution.DistributionError):
             android_sdk.register_android_tool(os.path.join("build-tools", "19.1.0", "random_tool"))
Ejemplo n.º 54
0
 def test_sdk_path(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         self.assertEquals(sdk, android_sdk._sdk_path)
 def test_sdk_path(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         self.assertEquals(sdk, android_sdk._sdk_path)