Beispiel #1
0
    def test_get_distributions_error_ndk_api_mismatch(self, mock_glob,
                                                      mock_exists,
                                                      mock_get_dists):
        """Test that method
        :meth:`~pythonforandroid.distribution.Distribution.get_distribution`
        raises an error in case that we have some distribution already build,
        with a given `name` and `ndk_api`, and we try to get another
        distribution with the same `name` but different `ndk_api`.
        """
        expected_dist = Distribution.get_distribution(
            self.ctx,
            name="test_prj",
            recipes=["python3", "kivy"],
            arch_name=self.TEST_ARCH,
        )
        mock_get_dists.return_value = [expected_dist]
        mock_glob.return_value = ["sdl2-python3"]

        with self.assertRaises(BuildInterruptingException) as e:
            self.setUp_distribution_with_bootstrap(
                Bootstrap().get_bootstrap("sdl2", self.ctx),
                allow_replace_dist=False,
                ndk_api=22,
            )
        self.assertEqual(
            e.exception.args[0],
            "Asked for dist with name test_prj with recipes (python3, kivy)"
            " and NDK API 22, but a dist with this name already exists and has"
            " either incompatible recipes (python3, kivy) or NDK API 21",
        )
 def setUp_distribution_with_bootstrap(self, bs):
     """
     Extend the setUp by configuring a distribution, because some test
     needs a distribution to be set to be properly tested
     """
     self.ctx.bootstrap = bs
     self.ctx.bootstrap.distribution = Distribution.get_distribution(
         self.ctx, name="test_prj", recipes=["python3", "kivy"])
Beispiel #3
0
def dist_from_args(ctx, args):
    '''Parses out any distribution-related arguments, and uses them to
    obtain a Distribution class instance for the build.
    '''
    return Distribution.get_distribution(
        ctx,
        name=args.dist_name,
        recipes=split_argument_list(args.requirements),
        require_perfect_match=args.require_perfect_match)
Beispiel #4
0
def dist_from_args(ctx, args):
    '''Parses out any distribution-related arguments, and uses them to
    obtain a Distribution class instance for the build.
    '''
    return Distribution.get_distribution(
        ctx,
        name=args.dist_name,
        recipes=split_argument_list(args.requirements),
        require_perfect_match=args.require_perfect_match)
Beispiel #5
0
 def test_get_distribution_no_name(self, mock_exists):
     """Test that method
     :meth:`~pythonforandroid.distribution.Distribution.get_distribution`
     returns the proper result which should `unnamed_dist_1`."""
     mock_exists.return_value = False
     self.ctx.bootstrap = Bootstrap().get_bootstrap("sdl2", self.ctx)
     dist = Distribution.get_distribution(self.ctx,
                                          arch_name=self.TEST_ARCH)
     self.assertEqual(dist.name, "unnamed_dist_1")
Beispiel #6
0
 def setUp_distribution_with_bootstrap(self, bs, **kwargs):
     """Extend the setUp by configuring a distribution, because some test
     needs a distribution to be set to be properly tested"""
     self.ctx.bootstrap = bs
     self.ctx.bootstrap.distribution = Distribution.get_distribution(
         self.ctx,
         name=kwargs.pop("name", "test_prj"),
         recipes=kwargs.pop("recipes", ["python3", "kivy"]),
         arch_name=self.TEST_ARCH,
         **kwargs)
Beispiel #7
0
def dist_from_args(ctx, args):
    """Parses out any distribution-related arguments, and uses them to
    obtain a Distribution class instance for the build.
    """
    return Distribution.get_distribution(
        ctx,
        name=args.dist_name,
        ndk_api=args.ndk_api,
        recipes=split_argument_list(args.requirements),
        require_perfect_match=args.require_perfect_match,
        allow_replace_dist=args.allow_replace_dist)
 def setUp(self):
     self.ctx = Context()
     self.ctx.ndk_api = 21
     self.ctx.android_api = 27
     self.ctx._sdk_dir = "/opt/android/android-sdk"
     self.ctx._ndk_dir = "/opt/android/android-ndk"
     self.ctx.setup_dirs(os.getcwd())
     self.ctx.bootstrap = Bootstrap().get_bootstrap("sdl2", self.ctx)
     self.ctx.bootstrap.distribution = Distribution.get_distribution(
         self.ctx, name="sdl2", recipes=["python3", "kivy"])
     self.ctx.python_recipe = Recipe.get_recipe("python3", self.ctx)
def dist_from_args(ctx, args):
    """Parses out any distribution-related arguments, and uses them to
    obtain a Distribution class instance for the build.
    """
    return Distribution.get_distribution(
        ctx,
        name=args.dist_name,
        ndk_api=args.ndk_api,
        recipes=split_argument_list(args.requirements),
        require_perfect_match=args.require_perfect_match,
        allow_replace_dist=args.allow_replace_dist)
Beispiel #10
0
def dist_from_args(ctx, dist_args):
    '''Parses out any distribution-related arguments, and uses them to
    obtain a Distribution class instance for the build.
    '''
    return Distribution.get_distribution(
        ctx,
        name=dist_args.dist_name,
        recipes=split_argument_list(dist_args.requirements),
        allow_download=dist_args.allow_download,
        allow_build=dist_args.allow_build,
        extra_dist_dirs=split_argument_list(dist_args.extra_dist_dirs),
        require_perfect_match=dist_args.require_perfect_match)
Beispiel #11
0
    def distributions(self, args):
        '''Lists all distributions currently available (i.e. that have already
        been built).'''
        ctx = self.ctx
        dists = Distribution.get_distributions(ctx)

        if dists:
            print('{Style.BRIGHT}Distributions currently installed are:'
                  '{Style.RESET_ALL}'.format(Style=Out_Style, Fore=Out_Fore))
            pretty_log_dists(dists, print)
        else:
            print('{Style.BRIGHT}There are no dists currently built.'
                  '{Style.RESET_ALL}'.format(Style=Out_Style))
    def distributions(self, args):
        '''Lists all distributions currently available (i.e. that have already
        been built).'''
        ctx = self.ctx
        dists = Distribution.get_distributions(ctx)

        if dists:
            print('{Style.BRIGHT}Distributions currently installed are:'
                  '{Style.RESET_ALL}'.format(Style=Out_Style, Fore=Out_Fore))
            pretty_log_dists(dists, print)
        else:
            print('{Style.BRIGHT}There are no dists currently built.'
                  '{Style.RESET_ALL}'.format(Style=Out_Style))
Beispiel #13
0
 def setUp(self):
     self.ctx = Context()
     self.ctx.ndk_api = 21
     self.ctx.android_api = 27
     self.ctx._sdk_dir = "/opt/android/android-sdk"
     self.ctx._ndk_dir = "/opt/android/android-ndk"
     self.ctx.setup_dirs(os.getcwd())
     self.ctx.bootstrap = Bootstrap().get_bootstrap("sdl2", self.ctx)
     self.ctx.bootstrap.distribution = Distribution.get_distribution(
         self.ctx, name="sdl2", recipes=["python3", "kivy"])
     self.ctx.python_recipe = Recipe.get_recipe("python3", self.ctx)
     # Here we define the expected compiler, which, as per ndk >= r19,
     # should be the same for all the tests (no more gcc compiler)
     self.expected_compiler = ("/opt/android/android-ndk/toolchains/"
                               "llvm/prebuilt/linux-x86_64/bin/clang")
Beispiel #14
0
def dist_from_args(ctx, args):
    '''Parses out any distribution-related arguments, and uses them to
    obtain a Distribution class instance for the build.
    '''
    #  check if distribution force build requested
    force_build = bool(os.environ.get('P4A_force_build')) or args.force_build
    dist = Distribution.get_distribution(
        ctx,
        name=args.dist_name,
        recipes=split_argument_list(args.requirements),
        force_build=force_build,
        extra_dist_dirs=split_argument_list(args.extra_dist_dirs),
        require_perfect_match=args.require_perfect_match)

    #  for distribution where user requested local recipe rebuild P4A_force_build set tue
    ctx.P4A_force_build = dist.P4A_force_build  #  see Distribution.get_distribution()
    return dist
Beispiel #15
0
 def test_get_distributions_possible_dists(self, mock_get_dists):
     """Test that method
     :meth:`~pythonforandroid.distribution.Distribution.get_distributions`
     returns the proper
     `:class:`~pythonforandroid.distribution.Distribution` in case that we
     already have it build and we request the same
     `:class:`~pythonforandroid.distribution.Distribution`.
     """
     expected_dist = Distribution.get_distribution(
         self.ctx,
         name="test_prj",
         recipes=["python3", "kivy"],
         arch_name=self.TEST_ARCH,
     )
     mock_get_dists.return_value = [expected_dist]
     self.setUp_distribution_with_bootstrap(Bootstrap().get_bootstrap(
         "sdl2", self.ctx),
                                            name="test_prj")
     dists = self.ctx.bootstrap.distribution.get_distributions(self.ctx)
     self.assertEqual(dists[0], expected_dist)