当前位置: 首页>>代码示例>>Python>>正文


Python main.main函数代码示例

本文整理汇总了Python中snapcraft.main.main函数的典型用法代码示例。如果您正苦于以下问题:Python main函数的具体用法?Python main怎么用?Python main使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了main函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_no_unicode_in_help_strings

    def test_no_unicode_in_help_strings(self, mock_stdout):
        helps = ['topics']

        for key in _TOPICS.keys():
            helps.append(str(key))

        # Get a list of plugins
        import snapcraft.plugins
        import os
        from pathlib import Path
        for plugin in Path(snapcraft.plugins.__path__[0]).glob('*.py'):
            if (os.path.isfile(str(plugin)) and
                    not os.path.basename(str(plugin)).startswith('_')):
                helps.append(os.path.basename(str(plugin)[:-3]))

        for key in helps:
            mock_stdout.truncate(0)
            mock_stdout.seek(0)
            with self.subTest(key=key):
                main(['help', key])
                try:
                    mock_stdout.getvalue().encode('ascii')
                except UnicodeEncodeError:
                    self.fail('Non-ASCII characters in help text for '
                              '{!r}'.format(key))
开发者ID:CavanJ,项目名称:snapcraft,代码行数:25,代码来源:test_commands_help.py

示例2: test_init_must_write_snapcraft_yaml

    def test_init_must_write_snapcraft_yaml(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)

        expected_yaml = """name: my-snap-name # you probably want to 'snapcraft register <name>'
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Single-line elevator pitch for your amazing snap # 79 char long summary
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

parts:
  my-part:
    # See 'snapcraft plugins'
    plugin: nil"""  # noqa, lines too long

        main(['init'])

        self.assertEqual(
            'Created snap/snapcraft.yaml.\nEdit the file to your liking or '
            'run `snapcraft` to get started\n', fake_logger.output)

        # Verify the generated yaml
        with open(os.path.join('snap', 'snapcraft.yaml'), 'r') as f:
            self.assertEqual(f.read(), expected_yaml)
开发者ID:josepht,项目名称:snapcraft,代码行数:30,代码来源:test_init.py

示例3: test_gated_unknown_snap

    def test_gated_unknown_snap(self):
        self.client.login('dummy', 'test correct password')

        with self.assertRaises(SystemExit):
            main([self.command_name, 'notfound'])
        self.assertIn("Snap 'notfound' was not found.",
                      self.fake_logger.output)
开发者ID:fgimenez,项目名称:snapcraft,代码行数:7,代码来源:test_commands_gated.py

示例4: test_sign_build_push_successfully

    def test_sign_build_push_successfully(
            self, mock_installed, mock_get_snap_data, mock_check_output,
            mock_get_account_info, mock_push_snap_build):
        mock_installed.return_value = True
        mock_get_account_info.return_value = {
            'account_id': 'abcd',
            'account_keys': [{'public-key-sha3-384': 'a_hash'}],
            'snaps': {
                '16': {
                    'test-snap': {'snap-id': 'snap-id'},
                }
            }
        }
        mock_get_snap_data.return_value = {
            'name': 'test-snap',
            'grade': 'stable',
        }
        mock_check_output.side_effect = [
            '[{"name": "default", "sha3-384": "a_hash"}]',
            b'Mocked assertion'
        ]

        main(['sign-build', self.snap_test.snap_path])

        snap_build_path = self.snap_test.snap_path + '-build'
        self.assertTrue(os.path.exists(snap_build_path))
        self.assertEqual([
            'Build assertion {} saved to disk.'.format(snap_build_path),
            'Build assertion {} pushed to the Store.'.format(snap_build_path),
        ], self.fake_logger.output.splitlines())
        mock_check_output.assert_called_with([
            'snap', 'sign-build', '--developer-id=abcd', '--snap-id=snap-id',
            '--grade=stable', '-k', 'default', self.snap_test.snap_path,
        ])
        mock_push_snap_build.assert_called_with('snap-id', 'Mocked assertion')
开发者ID:cwayne18,项目名称:snapcraft,代码行数:35,代码来源:test_commands_sign_build.py

示例5: test_partial_clean

    def test_partial_clean(self):
        parts = self.make_snapcraft_yaml(n=3)

        main(['clean', 'clean0', 'clean2'])

        for i in [0, 2]:
            self.assertFalse(
                os.path.exists(parts[i]['part_dir']),
                'Expected for {!r} to be wiped'.format(parts[i]['part_dir']))

        self.assertTrue(os.path.exists(parts[1]['part_dir']),
                        'Expected a part directory for the clean1 part')

        self.assertTrue(os.path.exists(self.parts_dir))
        self.assertTrue(os.path.exists(self.stage_dir))
        self.assertTrue(os.path.exists(self.prime_dir))

        # Now clean it the rest of the way
        main(['clean', 'clean1'])

        for i in range(0, 3):
            self.assertFalse(
                os.path.exists(parts[i]['part_dir']),
                'Expected for {!r} to be wiped'.format(parts[i]['part_dir']))

        self.assertFalse(os.path.exists(self.parts_dir))
        self.assertFalse(os.path.exists(self.stage_dir))
        self.assertFalse(os.path.exists(self.prime_dir))
开发者ID:squidsoup,项目名称:snapcraft,代码行数:28,代码来源:test_clean.py

示例6: test_sign_build_no_usable_keys

    def test_sign_build_no_usable_keys(
            self, mock_installed, mock_get_snap_data, mock_check_output,
            mock_get_account_info):
        mock_installed.return_value = True
        mock_get_account_info.return_value = {
            'account_id': 'abcd',
            'snaps': {
                '16': {
                    'test-snap': {'snap-id': 'snap-id'},
                }
            }
        }
        mock_get_snap_data.return_value = {
            'name': 'test-snap',
            'grade': 'stable',
        }
        mock_check_output.side_effect = [
            '[]',
        ]

        with self.assertRaises(SystemExit) as raised:
            main(['sign-build', self.snap_test.snap_path])

        self.assertEqual(1, raised.exception.code)
        self.assertEqual([
            'You have no usable keys.',
            'Please create at least one key with `snapcraft create-key` '
            'for use with snap.',
            ], self.fake_logger.output.splitlines())

        snap_build_path = self.snap_test.snap_path + '-build'
        self.assertFalse(os.path.exists(snap_build_path))
开发者ID:cwayne18,项目名称:snapcraft,代码行数:32,代码来源:test_commands_sign_build.py

示例7: test_sign_build_unregistered_key

    def test_sign_build_unregistered_key(
            self, mock_installed, mock_get_snap_data, mock_check_output,
            mock_get_account_info):
        mock_installed.return_value = True
        mock_get_account_info.return_value = {
            'account_id': 'abcd',
            'account_keys': [{'public-key-sha3-384': 'another_hash'}],
            'snaps': {
                '16': {
                    'test-snap': {'snap-id': 'snap-id'},
                }
            }
        }
        mock_get_snap_data.return_value = {
            'name': 'test-snap',
            'grade': 'stable',
        }
        mock_check_output.side_effect = [
            '[{"name": "default", "sha3-384": "a_hash"}]',
        ]

        with self.assertRaises(SystemExit) as raised:
            main(['sign-build', self.snap_test.snap_path])

        self.assertEqual(1, raised.exception.code)
        self.assertEqual([
            'The key \'default\' is not registered in the Store.',
            'Please register it with `snapcraft register-key \'default\'` '
            'before signing and pushing signatures to the Store.',
        ], self.fake_logger.output.splitlines())
        snap_build_path = self.snap_test.snap_path + '-build'
        self.assertFalse(os.path.exists(snap_build_path))
开发者ID:cwayne18,项目名称:snapcraft,代码行数:32,代码来源:test_commands_sign_build.py

示例8: test_snap_with_output

    def test_snap_with_output(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)
        self.make_snapcraft_yaml()

        main(['snap', '--output', 'mysnap.snap'])

        self.assertEqual(
            'Preparing to pull part1 \n'
            'Pulling part1 \n'
            'Preparing to build part1 \n'
            'Building part1 \n'
            'Staging part1 \n'
            'Priming part1 \n'
            'Snapping \'snap-test\' ...\n'
            'Snapped mysnap.snap\n',
            fake_logger.output)

        self.assertTrue(os.path.exists(self.stage_dir),
                        'Expected a stage directory')

        self.verify_state('part1', self.state_dir, 'prime')

        self.popen_spy.assert_called_once_with([
            'mksquashfs', self.snap_dir, 'mysnap.snap',
            '-noappend', '-comp', 'xz', '-no-xattrs', '-all-root'],
            stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

        self.assertThat('mysnap.snap', FileExists())
开发者ID:SamYaple,项目名称:snapcraft,代码行数:29,代码来源:test_commands_snap.py

示例9: test_snap_defaults_on_a_tty

    def test_snap_defaults_on_a_tty(self, progress_mock):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)
        self.make_snapcraft_yaml()
        self.isatty_mock.return_value = True

        main(['snap'])

        self.assertEqual(
            'Preparing to pull part1 \n'
            'Pulling part1 \n'
            'Preparing to build part1 \n'
            'Building part1 \n'
            'Staging part1 \n'
            'Priming part1 \n'
            'Snapped snap-test_1.0_amd64.snap\n',
            fake_logger.output)

        self.assertTrue(os.path.exists(self.stage_dir),
                        'Expected a stage directory')

        self.verify_state('part1', self.state_dir, 'prime')

        self.popen_spy.assert_called_once_with([
            'mksquashfs', self.snap_dir, 'snap-test_1.0_amd64.snap',
            '-noappend', '-comp', 'xz', '-no-xattrs', '-all-root'],
            stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

        self.assertThat('snap-test_1.0_amd64.snap', FileExists())
开发者ID:SamYaple,项目名称:snapcraft,代码行数:29,代码来源:test_commands_snap.py

示例10: test_snap_defaults_with_parts_in_prime

    def test_snap_defaults_with_parts_in_prime(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)
        self.make_snapcraft_yaml()

        # Pretend this part has already been primed
        os.makedirs(self.state_dir)
        open(os.path.join(self.state_dir, 'prime'), 'w').close()

        main(['snap'])

        self.assertEqual(
            'Skipping pull part1 (already ran)\n'
            'Skipping build part1 (already ran)\n'
            'Skipping stage part1 (already ran)\n'
            'Skipping prime part1 (already ran)\n'
            'Snapping \'snap-test\' ...\n'
            'Snapped snap-test_1.0_amd64.snap\n',
            fake_logger.output)

        self.popen_spy.assert_called_once_with([
            'mksquashfs', self.snap_dir, 'snap-test_1.0_amd64.snap',
            '-noappend', '-comp', 'xz', '-no-xattrs', '-all-root'],
            stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

        self.assertThat('snap-test_1.0_amd64.snap', FileExists())
开发者ID:SamYaple,项目名称:snapcraft,代码行数:26,代码来源:test_commands_snap.py

示例11: test_snap_from_dir_type_os_does_not_use_all_root

    def test_snap_from_dir_type_os_does_not_use_all_root(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)

        meta_dir = os.path.join('mysnap', 'meta')
        os.makedirs(meta_dir)
        with open(os.path.join(meta_dir, 'snap.yaml'), 'w') as f:
            f.write("""name: my_snap
version: 99
architectures: [amd64, armhf]
type: os
""")

        main(['snap', 'mysnap'])

        self.assertEqual(
            'Snapping \'my_snap\' ...\n'
            'Snapped my_snap_99_multi.snap\n',
            fake_logger.output)

        self.popen_spy.assert_called_once_with([
            'mksquashfs', os.path.abspath('mysnap'), 'my_snap_99_multi.snap',
            '-noappend', '-comp', 'xz', '-no-xattrs'],
            stderr=subprocess.STDOUT, stdout=subprocess.PIPE)

        self.assertThat('my_snap_99_multi.snap', FileExists())
开发者ID:SamYaple,项目名称:snapcraft,代码行数:26,代码来源:test_commands_snap.py

示例12: test_status_with_no_permissions

    def test_status_with_no_permissions(self):
        with self.assertRaises(SystemExit):
            main(['status', 'snap-test'])

        self.assertIn(
            'No valid credentials found. Have you run "snapcraft login"?',
            self.fake_logger.output)
开发者ID:cwayne18,项目名称:snapcraft,代码行数:7,代码来源:test_commands_status.py

示例13: test_snap_renames_stale_snap_build

    def test_snap_renames_stale_snap_build(self, mocked_time):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)
        self.make_snapcraft_yaml()

        mocked_time.return_value = 1234

        snap_build = 'snap-test_1.0_amd64.snap-build'
        with open(snap_build, 'w') as fd:
            fd.write('signed assertion?')

        main(['snap'])

        snap_build_renamed = snap_build + '.1234'
        self.assertEqual([
            'Preparing to pull part1 ',
            'Pulling part1 ',
            'Preparing to build part1 ',
            'Building part1 ',
            'Staging part1 ',
            'Priming part1 ',
            'Renaming stale build assertion to {}'.format(snap_build_renamed),
            'Snapping \'snap-test\' ...',
            'Snapped snap-test_1.0_amd64.snap',
            ], fake_logger.output.splitlines())

        self.assertThat('snap-test_1.0_amd64.snap', FileExists())
        self.assertThat(snap_build, Not(FileExists()))
        self.assertThat(snap_build_renamed, FileExists())
        self.assertThat(
            snap_build_renamed, FileContains('signed assertion?'))
开发者ID:3v1n0,项目名称:snapcraft,代码行数:31,代码来源:test_snap.py

示例14: test_stage_ran_twice_is_a_noop

    def test_stage_ran_twice_is_a_noop(self):
        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)
        parts = self.make_snapcraft_yaml()

        main(['stage'])

        self.assertEqual(
            'Preparing to pull stage0 \n'
            'Pulling stage0 \n'
            'Preparing to build stage0 \n'
            'Building stage0 \n'
            'Staging stage0 \n',
            fake_logger.output)

        self.assertTrue(os.path.exists(self.stage_dir),
                        'Expected a stage directory')
        self.assertTrue(os.path.exists(self.parts_dir),
                        'Expected a parts directory')
        self.assertTrue(os.path.exists(parts[0]['part_dir']),
                        'Expected a part directory for the build0 part')

        self.verify_state('build0', parts[0]['state_dir'], 'stage')

        fake_logger = fixtures.FakeLogger(level=logging.INFO)
        self.useFixture(fake_logger)

        main(['stage'])

        self.assertEqual(
            'Skipping pull stage0 (already ran)\n'
            'Skipping build stage0 (already ran)\n'
            'Skipping stage stage0 (already ran)\n',
            fake_logger.output)
开发者ID:squidsoup,项目名称:snapcraft,代码行数:34,代码来源:test_stage.py

示例15: test_list_plugins_large_terminal

    def test_list_plugins_large_terminal(self):
        self.maxDiff = None
        fake_terminal = fixture_setup.FakeTerminal(columns=999)
        self.useFixture(fake_terminal)

        main(['list-plugins'])
        self.assertEqual(fake_terminal.getvalue(), self.default_plugin_output)
开发者ID:SamYaple,项目名称:snapcraft,代码行数:7,代码来源:test_commands_list_plugins.py


注:本文中的snapcraft.main.main函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。