예제 #1
0
    def setUp(self):
        super().setUp()
        if os.getenv('SNAPCRAFT_FROM_INSTALLED', False):
            self.snapcraft_command = 'snapcraft'
            self.snapcraft_parser_command = 'snapcraft-parser'
        else:
            self.snapcraft_command = os.path.join(os.getcwd(), 'bin',
                                                  'snapcraft')
            self.snapcraft_parser_command = os.path.join(
                os.getcwd(), 'bin', 'snapcraft-parser')

        self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps')
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        self.useFixture(
            fixtures.EnvironmentVariable('XDG_CONFIG_HOME',
                                         os.path.join(self.path, '.config')))
        self.useFixture(
            fixtures.EnvironmentVariable('XDG_DATA_HOME',
                                         os.path.join(self.path, 'data')))
        self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb'))

        # Note that these directories won't exist when the test starts,
        # they might be created after calling the snapcraft command on the
        # project dir.
        self.parts_dir = 'parts'
        self.stage_dir = 'stage'
        self.prime_dir = 'prime'
예제 #2
0
    def setUp(self):
        super().setUp()
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path
        self.useFixture(fixture_setup.TempXDG(self.path))
        self.fake_terminal = fixture_setup.FakeTerminal()
        self.useFixture(self.fake_terminal)
        # Some tests will directly or indirectly change the plugindir, which
        # is a module variable. Make sure that it is returned to the original
        # value when a test ends.
        self.addCleanup(common.set_plugindir, common.get_plugindir())
        self.addCleanup(common.set_schemadir, common.get_schemadir())
        self.addCleanup(common.set_librariesdir, common.get_librariesdir())
        self.addCleanup(common.set_tourdir, common.get_tourdir())
        self.addCleanup(common.reset_env)
        common.set_schemadir(os.path.join(__file__, '..', '..', '..',
                                          'schema'))
        self.useFixture(fixtures.FakeLogger(level=logging.ERROR))

        patcher = mock.patch('multiprocessing.cpu_count')
        self.cpu_count = patcher.start()
        self.cpu_count.return_value = 2
        self.addCleanup(patcher.stop)

        patcher = mock.patch('snapcraft.internal.indicators.ProgressBar',
                             new=SilentProgressBar)
        patcher.start()
        self.addCleanup(patcher.stop)

        # These are what we expect by default
        self.snap_dir = os.path.join(os.getcwd(), 'prime')
        self.stage_dir = os.path.join(os.getcwd(), 'stage')
        self.parts_dir = os.path.join(os.getcwd(), 'parts')
        self.local_plugins_dir = os.path.join(self.parts_dir, 'plugins')
예제 #3
0
    def setUp(self):
        super().setUp()
        if os.getenv('SNAPCRAFT_FROM_INSTALLED', False):
            self.snapcraft_command = 'snapcraft'
            self.snapcraft_parser_command = 'snapcraft-parser'
        else:
            self.snapcraft_command = os.path.join(os.getcwd(), 'bin',
                                                  'snapcraft')
            self.snapcraft_parser_command = os.path.join(
                os.getcwd(), 'bin', 'snapcraft-parser')

        self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps')
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        self.useFixture(
            fixtures.EnvironmentVariable('XDG_CONFIG_HOME',
                                         os.path.join(self.path, '.config')))
        self.useFixture(
            fixtures.EnvironmentVariable('XDG_CACHE_HOME',
                                         os.path.join(self.path, '.cache')))
        self.useFixture(
            fixtures.EnvironmentVariable('XDG_DATA_HOME',
                                         os.path.join(self.path, 'data')))
        self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb'))

        patcher = mock.patch('xdg.BaseDirectory.xdg_config_home',
                             new=os.path.join(self.path, '.config'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch('xdg.BaseDirectory.xdg_data_home',
                             new=os.path.join(self.path, 'data'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch('xdg.BaseDirectory.xdg_cache_home',
                             new=os.path.join(self.path, '.cache'))
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher_dirs = mock.patch('xdg.BaseDirectory.xdg_config_dirs',
                                  new=[xdg.BaseDirectory.xdg_config_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        patcher_dirs = mock.patch('xdg.BaseDirectory.xdg_data_dirs',
                                  new=[xdg.BaseDirectory.xdg_data_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        # Note that these directories won't exist when the test starts,
        # they might be created after calling the snapcraft command on the
        # project dir.
        self.parts_dir = 'parts'
        self.stage_dir = 'stage'
        self.prime_dir = 'prime'

        self.deb_arch = _ProjectOptions().deb_arch
        self.distro_series = platform.linux_distribution()[2]
예제 #4
0
    def test_with_TEMPDIR_env_var(self):
        with tempfile.TemporaryDirectory() as test_tmp_dir:
            with fixtures.EnvironmentVariable('TMPDIR', test_tmp_dir):
                temp_cwd_fixture = fixture_setup.TempCWD()
                self.useFixture(temp_cwd_fixture)

        self.assertThat(os.path.dirname(temp_cwd_fixture.path),
                        Equals(test_tmp_dir))
예제 #5
0
    def setUp(self):
        super().setUp()
        snapcraft_bin = os.getenv('SNAPCRAFT', 'snapcraft')
        self.snapcraft_command = os.path.join(os.getcwd(), 'bin',
                                              snapcraft_bin)
        self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps')

        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path
예제 #6
0
    def setUp(self):
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        super().setUp()

        # Since we're running in a temporary directory use
        # the original source tree version of snapcraft-parser
        if not os.getenv('SNAPCRAFT_FROM_INSTALLED', False):
            self.snapcraft_parser_command = os.path.join(
                os.path.dirname(__file__), '..', 'bin', 'snapcraft-parser')
예제 #7
0
 def setUp(self):
     super().setUp()
     temp_cwd_fixture = fixture_setup.TempCWD()
     self.useFixture(temp_cwd_fixture)
     self.path = temp_cwd_fixture.path
     # Some tests will directly or indirectly change the plugindir, which
     # is a module variable. Make sure that it is returned to the original
     # value when a test ends.
     self.addCleanup(common.set_plugindir, common.get_plugindir())
     self.addCleanup(common.set_schemadir, common.get_schemadir())
예제 #8
0
    def setUp(self):
        super().setUp()
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path
        self.useFixture(fixture_setup.TempXDG(self.path))
        self.fake_terminal = fixture_setup.FakeTerminal()
        self.useFixture(self.fake_terminal)
        self.useFixture(fixture_setup.SilentSnapProgress())
        # Some tests will directly or indirectly change the plugindir, which
        # is a module variable. Make sure that it is returned to the original
        # value when a test ends.
        self.addCleanup(common.set_plugindir, common.get_plugindir())
        self.addCleanup(common.set_schemadir, common.get_schemadir())
        self.addCleanup(common.set_librariesdir, common.get_librariesdir())
        self.addCleanup(common.reset_env)
        common.set_schemadir(
            os.path.join(__file__, '..', '..', '..', '..', 'schema'))
        self.fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(self.fake_logger)

        patcher = mock.patch('multiprocessing.cpu_count')
        self.cpu_count = patcher.start()
        self.cpu_count.return_value = 2
        self.addCleanup(patcher.stop)

        patcher = mock.patch('snapcraft.internal.indicators.ProgressBar',
                             new=SilentProgressBar)
        patcher.start()
        self.addCleanup(patcher.stop)

        # These are what we expect by default
        self.snap_dir = os.path.join(os.getcwd(), 'snap')
        self.prime_dir = os.path.join(os.getcwd(), 'prime')
        self.stage_dir = os.path.join(os.getcwd(), 'stage')
        self.parts_dir = os.path.join(os.getcwd(), 'parts')
        self.local_plugins_dir = os.path.join(self.snap_dir, 'plugins')

        # Avoid installing patchelf in the tests
        self.useFixture(
            fixtures.EnvironmentVariable('SNAPCRAFT_NO_PATCHELF', '1'))

        machine = os.environ.get('SNAPCRAFT_TEST_MOCK_MACHINE', None)
        if machine:
            patcher = mock.patch('platform.machine')
            self.mock_machine = patcher.start()
            self.mock_machine.return_value = machine
            self.addCleanup(patcher.stop)
예제 #9
0
    def setUp(self):
        super().setUp()
        if os.getenv('SNAPCRAFT_FROM_INSTALLED', False):
            self.snapcraft_command = 'snapcraft'
        else:
            snapcraft_bin = os.getenv('SNAPCRAFT', 'snapcraft')
            self.snapcraft_command = os.path.join(
                os.getcwd(), 'bin', snapcraft_bin)

        self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps')
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        self.useFixture(fixtures.EnvironmentVariable(
            'XDG_CONFIG_HOME', os.path.join(self.path, '.config')))
예제 #10
0
 def setUp(self):
     super().setUp()
     temp_cwd_fixture = fixture_setup.TempCWD()
     self.useFixture(temp_cwd_fixture)
     self.path = temp_cwd_fixture.path
     # Some tests will directly or indirectly change the plugindir, which
     # is a module variable. Make sure that it is returned to the original
     # value when a test ends.
     self.addCleanup(common.set_plugindir, common.get_plugindir())
     self.addCleanup(common.set_schemadir, common.get_schemadir())
     self.addCleanup(common.set_schemadir, common.get_schemadir())
     self.addCleanup(common.set_enable_parallel_builds,
                     common.get_enable_parallel_builds())
     self.addCleanup(common.reset_env)
     common.set_schemadir(os.path.join(__file__, '..', '..', '..',
                                       'schema'))
     self.useFixture(fixtures.FakeLogger(level=logging.ERROR))
예제 #11
0
    def setUp(self):
        super().setUp()
        if os.getenv('SNAPCRAFT_FROM_SNAP', False):
            self.snapcraft_command = '/snap/bin/snapcraft'
        elif os.getenv('SNAPCRAFT_FROM_DEB', False):
            self.snapcraft_command = '/usr/bin/snapcraft'
            self.snapcraft_parser_command = '/usr/bin/snapcraft-parser'
        elif os.getenv('VIRTUAL_ENV'):
            self.snapcraft_command = os.path.join(
                os.getenv('VIRTUAL_ENV'), 'bin', 'snapcraft')
            self.snapcraft_parser_command = os.path.join(
                os.getenv('VIRTUAL_ENV'), 'bin', 'snapcraft-parser')
        else:
            raise EnvironmentError(
                'snapcraft is not setup correctly for testing. Either set '
                'SNAPCRAFT_FROM_SNAP or SNAPCRAFT_FROM_DEB to run from either '
                'the snap or deb, or make sure your venv is properly setup '
                'as described in HACKING.md.')

        if os.getenv('SNAPCRAFT_FROM_SNAP', False):
            self.patchelf_command = '/snap/snapcraft/current/bin/patchelf'
        else:
            self.patchelf_command = 'patchelf'

        self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps')
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        self.useFixture(fixtures.EnvironmentVariable(
            'XDG_CONFIG_HOME', os.path.join(self.path, '.config')))
        self.useFixture(fixtures.EnvironmentVariable(
            'XDG_CACHE_HOME', os.path.join(self.path, '.cache')))
        self.useFixture(fixtures.EnvironmentVariable(
            'XDG_DATA_HOME', os.path.join(self.path, 'data')))
        self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb'))

        patcher = mock.patch(
            'xdg.BaseDirectory.xdg_config_home',
            new=os.path.join(self.path, '.config'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch(
            'xdg.BaseDirectory.xdg_data_home',
            new=os.path.join(self.path, 'data'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch(
            'xdg.BaseDirectory.xdg_cache_home',
            new=os.path.join(self.path, '.cache'))
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher_dirs = mock.patch(
            'xdg.BaseDirectory.xdg_config_dirs',
            new=[xdg.BaseDirectory.xdg_config_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        patcher_dirs = mock.patch(
            'xdg.BaseDirectory.xdg_data_dirs',
            new=[xdg.BaseDirectory.xdg_data_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        # Note that these directories won't exist when the test starts,
        # they might be created after calling the snapcraft command on the
        # project dir.
        self.parts_dir = 'parts'
        self.stage_dir = 'stage'
        self.prime_dir = 'prime'

        project = _ProjectOptions()
        self.deb_arch = project.deb_arch
        self.arch_triplet = project.arch_triplet

        release = OsRelease()
        self.distro_series = release.version_codename()