• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright 2020 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Unittests for deployment."""
18import os
19import shutil
20import subprocess
21import tempfile
22import unittest
23from unittest import mock
24
25from deployment import PluginDeployment
26
27
28# pylint: disable=protected-access
29from aidegen.lib import config
30
31
32class DeploymentUnittests(unittest.TestCase):
33    """Unit tests for deployment.py."""
34
35    _TMP_DIR = None
36
37    def setUp(self):
38        """Prepare the testdata related path."""
39        DeploymentUnittests._TMP_DIR = tempfile.mkdtemp()
40        config.AidegenConfig._CONFIG_DIR = os.path.join(
41            DeploymentUnittests._TMP_DIR, '.config', 'asuite', 'aidegen')
42        config.AidegenConfig._CONFIG_FILE_PATH = os.path.join(
43            config.AidegenConfig._CONFIG_DIR,
44            config.AidegenConfig._DEFAULT_CONFIG_FILE)
45
46    def tearDown(self):
47        """Clear the testdata related path."""
48        shutil.rmtree(DeploymentUnittests._TMP_DIR)
49
50    @mock.patch('builtins.input')
51    def test_ask_for_install(self, mock_input):
52        """Test _ask_for_install."""
53        mock_input.return_value = 'y'
54        PluginDeployment()._ask_for_install()
55        self.assertTrue(mock_input.call)
56
57    @mock.patch.object(subprocess, 'check_call')
58    def test_build_jars(self, mock_check_call):
59        """Test _build_jars."""
60        PluginDeployment()._build_jars()
61        self.assertTrue(mock_check_call.call)
62
63    def test_write_read_selection(self):
64        """Test _read_selection and _write_selection."""
65        PluginDeployment._user_selection = 'yes'
66        self.assertEqual(PluginDeployment._user_selection, 'yes')
67        PluginDeployment._user_selection = 'no'
68        self.assertEqual(PluginDeployment._user_selection, 'no')
69