Пример #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)
Пример #2
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))
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
0
    def test_tool_registration(self):
        with self.distribution() as sdk:
            AndroidDistribution(sdk_path=sdk).register_android_tool(
                os.path.join(sdk, 'build-tools', '19.1.0', 'aapt'))

        with self.distribution() as sdk:
            AndroidDistribution(sdk_path=sdk).register_android_tool(
                os.path.join(sdk, 'platforms', 'android-19', 'android.jar'))

        with pytest.raises(AndroidDistribution.Error):
            AndroidDistribution(sdk_path=sdk).register_android_tool(
                os.path.join(sdk, 'build-tools', 'bad-number', 'aapt'))

        with pytest.raises(AndroidDistribution.Error):
            AndroidDistribution(sdk_path=sdk).register_android_tool(
                os.path.join(sdk, 'platforms', 'not-a-platform',
                             'android.jar'))
Пример #7
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)
  def test_locate_sdk_path(self, path=None):
    # We can set good/bad paths alike. No checks until tools are called.

    @contextmanager
    def env(**kwargs):
      environment = dict(ANDROID_HOME=None, ANDROID_SDK_HOME=None, ANDROID_SDK=None)
      environment.update(**kwargs)
      with environment_as(**environment):
        yield

    with self.distribution() as sdk:
      with env(ANDROooooD_HOME=sdk):
        AndroidDistribution.locate_sdk_path(path)

    with self.distribution() as sdk:
      with env(ANDROID_HOME=sdk):
        AndroidDistribution.locate_sdk_path(path)
Пример #9
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)
Пример #10
0
    def test_locate_sdk_path(self, path=None):
        # We can set good/bad paths alike. No checks until tools are called.

        @contextmanager
        def env(**kwargs):
            environment = dict(ANDROID_HOME=None,
                               ANDROID_SDK_HOME=None,
                               ANDROID_SDK=None)
            environment.update(**kwargs)
            with environment_as(**environment):
                yield

        with self.distribution() as sdk:
            with env(ANDROooooD_HOME=sdk):
                AndroidDistribution.locate_sdk_path(path)

        with self.distribution() as sdk:
            with env(ANDROID_HOME=sdk):
                AndroidDistribution.locate_sdk_path(path)
Пример #11
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()
Пример #12
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))
Пример #13
0
 def android_sdk(self):
     if self._android_sdk is None:
         self._android_sdk = AndroidDistribution.cached(self.forced_sdk)
     return self._android_sdk
Пример #14
0
 def android_sdk(self):
   """Instantiate an Android SDK distribution that provides tools to android tasks."""
   return AndroidDistribution.cached(self._sdk_path)
Пример #15
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"))
Пример #16
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)
 def test_register_android_tool_bad_sdk(self):
   with self.assertRaises(AndroidDistribution.DistributionError):
     sdk = os.path.join('/no', 'sdk', 'here')
     android_sdk = AndroidDistribution.cached(sdk)
     aapt = os.path.join('build-tools', '19.1.0', 'aapt')
     android_sdk.register_android_tool(aapt)
Пример #18
0
 def test_register_android_tool_bad_sdk(self):
     sdk = os.path.join("/no", "sdk", "here")
     android_sdk = AndroidDistribution.cached(sdk)
     aapt = os.path.join("build-tools", "19.1.0", "aapt")
     with self.assertRaises(AndroidDistribution.DistributionError):
         android_sdk.register_android_tool(aapt)
Пример #19
0
 def test_empty_sdk_path(self):
     # Shows that an AndroidDistribution can be created as long as an sdk path is declared.
     with temporary_dir() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         self.assertEquals(android_sdk._sdk_path, sdk)
 def test_register_nonexistent_android_tool(self):
   with self.assertRaises(AndroidDistribution.DistributionError):
     with self.distribution() as sdk:
       android_sdk = AndroidDistribution.cached(sdk)
       android_sdk.register_android_tool(os.path.join('build-tools', '19.1.0', 'random_tool'))
Пример #21
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_no_sdk_on_path(self):
   with self.assertRaises(AndroidDistribution.DistributionError):
     with self.distribution() as sdk:
       with self.env(ANDROooooD_HOME=sdk):
         dist = AndroidDistribution.locate_sdk_path()
         self.assertEquals(dist._sdk_path, None)
 def test_validated_tools(self):
   with self.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)
Пример #24
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)
Пример #25
0
 def test_sdk_path_is_none(self):
     with self.env() as sdk:
         with self.assertRaises(AndroidDistribution.DistributionError):
             AndroidDistribution.cached(sdk)
Пример #26
0
 def test_sdk_path(self):
     with distribution() as sdk:
         android_sdk = AndroidDistribution.cached(sdk)
         self.assertEquals(sdk, android_sdk._sdk_path)
Пример #27
0
 def test_validate_bad_path(self):
     # The SDK path is not validated until the tool is registered.
     sdk = os.path.join("/no", "sdk", "here")
     android_sdk = AndroidDistribution.cached(sdk)
     self.assertEquals(sdk, android_sdk._sdk_path)
Пример #28
0
 def android_sdk(self):
   if self._android_sdk is None:
     self._android_sdk = AndroidDistribution.cached(self.forced_sdk)
   return self._android_sdk
Пример #29
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))