Beispiel #1
0
    def test_assemble_snap(self, mock_stderr, mock_stdout, mock_snap):
        meta_dir = os.path.join('snap', 'meta')
        metadata = os.path.join(meta_dir, 'package.yaml')
        readme_md = os.path.join(meta_dir, 'readme.md')

        os.makedirs(meta_dir)
        with open(metadata, 'w') as f:
            f.write('''name: test-package
version: 1
vendor: me <*****@*****.**>
summary: test
description: test
icon: my-icon.png

binaries:
  - name: binary1
''')
        with open(readme_md, 'w') as f:
            f.write('''description
longer text.''')

        class Args:
            cmd = ''

        with self.assertRaises(SystemExit) as raised:
            cmds.assemble(Args())

        self.assertEqual(raised.exception.code, 0, 'Wrong exit code returned.')

        # we do a contains since review tools are something we don't control
        output_stdout = mock_stdout.getvalue()
        output_stderr = mock_stderr.getvalue()
        self.assertEqual(output_stderr, '', 'There should be no stderr')
        self.assertTrue('Snapping' in output_stdout)
        self.assertTrue('test-package_1_all.snap' in output_stdout)
Beispiel #2
0
    def test_assemble_snap_fails_on_bad_snap_layout(
            self, mock_stderr, mock_stdout, mock_snap):
        meta_dir = os.path.join('snap', 'meta')
        metadata = os.path.join(meta_dir, 'package.yaml')
        readme_md = os.path.join(meta_dir, 'readme.md')

        os.makedirs(meta_dir)
        with open(metadata, 'w') as f:
            f.write('')
        with open(readme_md, 'w') as f:
            f.write('')

        class Args:
            cmd = ''

        with self.assertRaises(SystemExit) as raised:
            cmds.assemble(Args())

        self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.')

        # we do a contains since review tools are something we don't control
        output_stdout = mock_stdout.getvalue()
        output_stderr = mock_stderr.getvalue()
        self.assertTrue('can not parse package.yaml: missing required fields'
                        in output_stderr)
        self.assertTrue('Snapping' in output_stdout)
        self.assertFalse('test-package_1_all.snap' in output_stdout)