~longsleep/snapcraft/snapcraft-debs-plugin

« back to all changes in this revision

Viewing changes to snapcraft/tests/test_yaml.py

  • Committer: Snappy Tarmac
  • Author(s): Sergio Schvezov
  • Date: 2015-09-14 17:51:52 UTC
  • mfrom: (143.6.11 filesets)
  • Revision ID: snappy_tarmac-20150914175152-6digtk1bal2ppooq
Filesets based filtering for stage and snap by sergiusens approved by sergiusens,mvo

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    stage-packages: [fswebcam]
62
62
""")
63
63
        snapcraft.yaml.Config()
64
 
        mock_loadPlugin.assert_called_with("part1", "go", {
65
 
            "stage-packages": ["fswebcam"],
 
64
        mock_loadPlugin.assert_called_with('part1', 'go', {
 
65
            'stage-packages': ['fswebcam'],
 
66
            'stage': [], 'snap': [],
66
67
        })
67
68
 
68
69
    def test_config_raises_on_missing_snapcraft_yaml(self):
211
212
            'found character \'\\t\' that cannot start any token '
212
213
            'on line 2 of snapcraft.yaml')
213
214
 
 
215
    @unittest.mock.patch('snapcraft.yaml.Config.load_plugin')
 
216
    def test_config_expands_filesets(self, mock_loadPlugin):
 
217
        self.make_snapcraft_yaml("""name: test
 
218
version: "1"
 
219
vendor: me <me@me.com>
 
220
summary: test
 
221
description: test
 
222
icon: my-icon.png
 
223
 
 
224
parts:
 
225
  part1:
 
226
    type: go
 
227
    stage-packages: [fswebcam]
 
228
    filesets:
 
229
      wget:
 
230
        - /usr/lib/wget.so
 
231
        - /usr/bin/wget
 
232
      build-wget:
 
233
        - /usr/lib/wget.a
 
234
    stage:
 
235
      - $wget
 
236
      - $build-wget
 
237
    snap:
 
238
      - $wget
 
239
      - /usr/share/my-icon.png
 
240
""")
 
241
        snapcraft.yaml.Config()
 
242
 
 
243
        mock_loadPlugin.assert_called_with('part1', 'go', {
 
244
            'snap': ['/usr/lib/wget.so', '/usr/bin/wget', '/usr/share/my-icon.png'],
 
245
            'stage-packages': ['fswebcam'],
 
246
            'stage': ['/usr/lib/wget.so', '/usr/bin/wget', '/usr/lib/wget.a'],
 
247
        })
 
248
 
214
249
 
215
250
class TestValidation(TestCase):
216
251
 
354
389
 
355
390
        expected_message = '\'my-icon.png\' is not a \'icon-path\''
356
391
        self.assertEqual(raised.exception.message, expected_message, msg=self.data)
 
392
 
 
393
 
 
394
class TestFilesets(TestCase):
 
395
 
 
396
    def setUp(self):
 
397
        super().setUp()
 
398
 
 
399
        self.properties = {
 
400
            'filesets': {
 
401
                '1': ['1', '2', '3'],
 
402
                '2': [],
 
403
            }
 
404
        }
 
405
 
 
406
    def test_expand_var(self):
 
407
        self.properties['stage'] = ['$1']
 
408
 
 
409
        fs = snapcraft.yaml._expand_filesets_for('stage', self.properties)
 
410
        self.assertEqual(fs, ['1', '2', '3'])
 
411
 
 
412
    def test_no_expansion(self):
 
413
        self.properties['stage'] = ['1']
 
414
 
 
415
        fs = snapcraft.yaml._expand_filesets_for('stage', self.properties)
 
416
        self.assertEqual(fs, ['1'])
 
417
 
 
418
    def test_invalid_expansion(self):
 
419
        self.properties['stage'] = ['$3']
 
420
 
 
421
        with self.assertRaises(snapcraft.yaml.SnapcraftLogicError) as raised:
 
422
            snapcraft.yaml._expand_filesets_for('stage', self.properties)
 
423
 
 
424
        self.assertEqual(
 
425
            raised.exception.message,
 
426
            '\'$3\' referred to in the \'stage\' fileset but it is not '
 
427
            'in filesets')