def test_create_gadget_meta_with_missing_gadget_yaml_raises_error(self): self.config_data['type'] = 'gadget' with self.assertRaises(MissingGadgetError): create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir)
def test_create_meta_with_declared_icon_and_setup(self): fake_logger = fixtures.FakeLogger(level=logging.INFO) self.useFixture(fake_logger) gui_path = os.path.join('setup', 'gui') os.makedirs(gui_path) setup_icon_content = b'setup icon' with open(os.path.join(gui_path, 'icon.png'), 'wb') as f: f.write(setup_icon_content) declared_icon_content = b'declared icon' with open('my-icon.png', 'wb') as f: f.write(declared_icon_content) self.config_data['icon'] = 'my-icon.png' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_icon = os.path.join(self.meta_dir, 'gui', 'icon.png') self.assertTrue(os.path.exists(expected_icon), 'icon.png was not setup correctly') with open(expected_icon, 'rb') as f: self.assertEqual(f.read(), declared_icon_content) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('icon' in y, 'icon found in snap.yaml {}'.format(y))
def test_create_meta_with_declared_icon_and_setup(self): fake_logger = fixtures.FakeLogger(level=logging.INFO) self.useFixture(fake_logger) gui_path = os.path.join('setup', 'gui') os.makedirs(gui_path) icon_content = b'this is the icon' with open(os.path.join(gui_path, 'icon.png'), 'wb') as f: f.write(icon_content) open(os.path.join(os.curdir, 'my-icon.png'), 'w').close() self.config_data['icon'] = 'my-icon.png' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_icon = os.path.join(self.meta_dir, 'gui', 'icon.png') self.assertTrue(os.path.exists(expected_icon), 'icon.png was not setup correctly') with open(expected_icon, 'rb') as f: self.assertEqual(f.read(), icon_content) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') self.assertTrue( "DEPRECATED: 'icon' defined in snapcraft.yaml" in fake_logger.output, 'Missing deprecation message for icon') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('icon' in y, 'icon found in snap.yaml {}'.format(y))
def test_create_meta_with_declared_icon_and_setup(self): fake_logger = fixtures.FakeLogger(level=logging.INFO) self.useFixture(fake_logger) gui_path = os.path.join('setup', 'gui') os.makedirs(gui_path) setup_icon_content = b'setup icon' with open(os.path.join(gui_path, 'icon.png'), 'wb') as f: f.write(setup_icon_content) declared_icon_content = b'declared icon' with open('my-icon.png', 'wb') as f: f.write(declared_icon_content) self.config_data['icon'] = 'my-icon.png' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_icon = os.path.join(self.meta_dir, 'gui', 'icon.png') self.assertTrue(os.path.exists(expected_icon), 'icon.png was not setup correctly') with open(expected_icon, 'rb') as f: self.assertEqual(f.read(), declared_icon_content) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('icon' in y, 'icon found in snap.yaml {}'.format(y))
def _create_meta(self, step, part_names): if step == steps.PRIME and part_names == self.config.part_names: common.env = self.config.snap_env() meta.create_snap_packaging( self.config.data, self.config.parts, self.project_options, self.config.snapcraft_yaml_path, self.config.original_snapcraft_yaml, self.config.validator.schema)
def generate_meta_yaml(self): create_snap_packaging(self.config_data, self.project_options) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: return yaml.load(f)
def generate_meta_yaml(self): create_snap_packaging(self.config_data, self.project_options, 'dummy') self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: return yaml.load(f)
def _create_meta(self, step, part_names): if step == steps.PRIME and part_names == self.config.part_names: common.env = self.config.snap_env() meta.create_snap_packaging( self.config.data, self.config.parts, self.project, self.config.validator.schema, )
def test_create_gadget_meta_with_gadget_yaml(self): gadget_yaml = 'stub entry: stub value' _create_file('gadget.yaml', content=gadget_yaml) self.config_data['type'] = 'gadget' create_snap_packaging(self.config_data, self.project_options, 'dummy') expected_gadget = os.path.join(self.meta_dir, 'gadget.yaml') self.assertTrue(os.path.exists(expected_gadget)) self.assertThat(expected_gadget, FileContains(gadget_yaml))
def test_create_meta_with_app(self): os.mkdir(self.snap_dir) open(os.path.join(self.snap_dir, 'app.sh'), 'w').close() self.config_data['apps'] = { 'app1': {'command': 'app.sh'}, 'app2': {'command': 'app.sh', 'plugs': ['network']}, 'app3': {'command': 'app.sh', 'plugs': ['network-server']} } self.config_data['plugs'] = { 'network-server': {'interface': 'network-bind'}} create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) for app in ['app1', 'app2', 'app3']: app_wrapper_path = os.path.join( self.snap_dir, 'command-{}.wrapper'.format(app)) self.assertTrue( os.path.exists(app_wrapper_path), 'the wrapper for {!r} was not setup correctly'.format(app)) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) expected = { 'architectures': ['amd64'], 'apps': { 'app1': { 'command': 'command-app1.wrapper', }, 'app2': { 'command': 'command-app2.wrapper', 'plugs': ['network'], }, 'app3': { 'command': 'command-app3.wrapper', 'plugs': ['network-server'], }, }, 'description': 'my description', 'summary': 'my summary', 'name': 'my-package', 'version': '1.0', 'plugs': { 'network-server': { 'interface': 'network-bind', } } } self.assertEqual(y, expected)
def test_create_gadget_meta_with_gadget_yaml(self): gadget_yaml = 'stub entry: stub value' with open(os.path.join('gadget.yaml'), 'w') as f: f.write(gadget_yaml) self.config_data['type'] = 'gadget' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_gadget = os.path.join(self.meta_dir, 'gadget.yaml') self.assertTrue(os.path.exists(expected_gadget)) with open(expected_gadget) as f: self.assertEqual(f.read(), gadget_yaml)
def test_create_meta_with_declared_icon_and_setup_ran_twice_ok(self): gui_path = os.path.join('setup', 'gui') os.makedirs(gui_path) icon_content = 'setup icon' _create_file(os.path.join(gui_path, 'icon.png'), content=icon_content) _create_file('my-icon.png') self.config_data['icon'] = 'my-icon.png' create_snap_packaging(self.config_data, self.project_options, 'dummy') # Running again should be good create_snap_packaging(self.config_data, self.project_options, 'dummy')
def test_create_meta_with_grade(self): self.config_data['grade'] = self.grade create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue('grade' in y, 'Expected "grade" property to be in snap.yaml') self.assertEqual(y['grade'], self.grade)
def test_create_gadget_meta_with_gadget_yaml(self): gadget_yaml = 'stub entry: stub value' with open(os.path.join('gadget.yaml'), 'w') as f: f.write(gadget_yaml) self.config_data['type'] = 'gadget' create_snap_packaging(self.config_data, self.project_options) expected_gadget = os.path.join(self.meta_dir, 'gadget.yaml') self.assertTrue(os.path.exists(expected_gadget)) with open(expected_gadget) as f: self.assertEqual(f.read(), gadget_yaml)
def test_create_meta_with_assumes(self): self.config_data['assumes'] = ['feature1', 'feature2'] create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'assumes' in y, 'Expected "assumes" property to be copied into snap.yaml') self.assertEqual(y['assumes'], ['feature1', 'feature2'])
def test_create_meta_with_epoch(self): self.config_data['epoch'] = '1*' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'epoch' in y, 'Expected "epoch" property to be copied into snap.yaml') self.assertEqual(y['epoch'], '1*')
def test_create_meta_with_declared_icon_and_setup_ran_twice_ok(self): gui_path = os.path.join('setup', 'gui') os.makedirs(gui_path) icon_content = b'this is the icon' with open(os.path.join(gui_path, 'icon.png'), 'wb') as f: f.write(icon_content) open(os.path.join(os.curdir, 'my-icon.png'), 'w').close() self.config_data['icon'] = 'my-icon.png' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) # Running again should be good create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir)
def test_create_meta_with_assumes(self): self.config_data['assumes'] = ['feature1', 'feature2'] create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'assumes' in y, 'Expected "assumes" property to be copied into snap.yaml') self.assertEqual(y['assumes'], ['feature1', 'feature2'])
def test_create_meta_with_epoch(self): self.config_data['epoch'] = '1*' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'epoch' in y, 'Expected "epoch" property to be copied into snap.yaml') self.assertEqual(y['epoch'], '1*')
def test_create_meta(self): create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) expected = {'architectures': ['amd64'], 'description': 'my description', 'summary': 'my summary', 'name': 'my-package', 'version': '1.0'} self.assertEqual(y, expected)
def test_create_meta_with_declared_icon(self): open(os.path.join(os.curdir, 'my-icon.png'), 'w').close() self.config_data['icon'] = 'my-icon.png' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(os.path.join(self.meta_dir, 'gui', 'icon.png')), 'icon.png was not setup correctly') self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('icon' in y, 'icon found in snap.yaml {}'.format(y))
def test_create_meta_with_declared_license(self): open(os.path.join(os.curdir, 'LICENSE'), 'w').close() self.config_data['license'] = 'LICENSE' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(os.path.join(self.meta_dir, 'license.txt')), 'license.txt was not setup correctly') self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('license' in y, 'license found in snap.yaml {}'.format(y))
def test_create_meta_with_declared_icon(self): open(os.path.join(os.curdir, 'my-icon.png'), 'w').close() self.config_data['icon'] = 'my-icon.png' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(os.path.join(self.meta_dir, 'gui', 'icon.png')), 'icon.png was not setup correctly') self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('icon' in y, 'icon found in snap.yaml {}'.format(y))
def test_create_meta_with_declared_license(self): open(os.path.join(os.curdir, 'LICENSE'), 'w').close() self.config_data['license'] = 'LICENSE' create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(os.path.join(self.meta_dir, 'license.txt')), 'license.txt was not setup correctly') self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('license' in y, 'license found in snap.yaml {}'.format(y))
def test_create_meta_with_license_in_setup(self): os.mkdir('setup') license_text = 'this is the license' with open(os.path.join('setup', 'license.txt'), 'w') as f: f.write(license_text) create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_license = os.path.join(self.meta_dir, 'license.txt') self.assertTrue(os.path.exists(expected_license), 'license.txt was not setup correctly') with open(expected_license) as f: self.assertEqual(f.read(), license_text) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('license' in y, 'license found in snap.yaml {}'.format(y))
def test_create_meta_with_license_in_setup(self): os.mkdir('setup') license_text = 'this is the license' with open(os.path.join('setup', 'license.txt'), 'w') as f: f.write(license_text) create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_license = os.path.join(self.meta_dir, 'license.txt') self.assertTrue(os.path.exists(expected_license), 'license.txt was not setup correctly') with open(expected_license) as f: self.assertEqual(f.read(), license_text) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('license' in y, 'license found in snap.yaml {}'.format(y))
def test_create_meta_with_icon_in_setup(self): gui_path = os.path.join('setup', 'gui') os.makedirs(gui_path) icon_content = b'this is the icon' with open(os.path.join(gui_path, 'icon.png'), 'wb') as f: f.write(icon_content) create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_icon = os.path.join(self.meta_dir, 'gui', 'icon.png') self.assertTrue(os.path.exists(expected_icon), 'icon.png was not setup correctly') with open(expected_icon, 'rb') as f: self.assertEqual(f.read(), icon_content) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('icon' in y, 'icon found in snap.yaml {}'.format(y))
def test_create_meta_with_grade(self): grade_types = [ 'stable', 'devel', ] for grade_type in grade_types: with self.subTest(key=grade_type): self.config_data['grade'] = grade_type create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'grade' in y, 'Expected "grade" property to be in snap.yaml') self.assertEqual(y['grade'], grade_type)
def test_create_meta_with_icon_in_setup(self): gui_path = os.path.join('setup', 'gui') os.makedirs(gui_path) icon_content = b'this is the icon' with open(os.path.join(gui_path, 'icon.png'), 'wb') as f: f.write(icon_content) create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) expected_icon = os.path.join(self.meta_dir, 'gui', 'icon.png') self.assertTrue(os.path.exists(expected_icon), 'icon.png was not setup correctly') with open(expected_icon, 'rb') as f: self.assertEqual(f.read(), icon_content) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertFalse('icon' in y, 'icon found in snap.yaml {}'.format(y))
def test_create_meta_with_confinement(self): confinement_types = [ 'strict', 'devmode', ] for confinement_type in confinement_types: with self.subTest(key=confinement_type): self.config_data['confinement'] = confinement_type create_snap_packaging(self.config_data, self.snap_dir, self.parts_dir) self.assertTrue(os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'confinement' in y, 'Expected "confinement" property to be in snap.yaml') self.assertEqual(y['confinement'], confinement_type)
def test_create_meta_with_confinement(self): confinement_types = [ 'strict', 'devmode', ] for confinement_type in confinement_types: with self.subTest(key=confinement_type): self.config_data['confinement'] = confinement_type create_snap_packaging( self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'confinement' in y, 'Expected "confinement" property to be in snap.yaml') self.assertEqual(y['confinement'], confinement_type)
def test_create_meta_with_grade(self): grade_types = [ 'stable', 'devel', ] for grade_type in grade_types: with self.subTest(key=grade_type): self.config_data['grade'] = grade_type create_snap_packaging( self.config_data, self.snap_dir, self.parts_dir) self.assertTrue( os.path.exists(self.snap_yaml), 'snap.yaml was not created') with open(self.snap_yaml) as f: y = yaml.load(f) self.assertTrue( 'grade' in y, 'Expected "grade" property to be in snap.yaml') self.assertEqual(y['grade'], grade_type)
def _create_meta(self, step, part_names): if step == 'prime' and part_names == self.config.part_names: common.env = self.config.snap_env() meta.create_snap_packaging(self.config.data, self.project_options)
def _create_meta(self, step, part_names): if step == 'prime' and part_names == self.config.part_names: common.env = self.config.snap_env() meta.create_snap_packaging(self.config.data, self.project_options.snap_dir, self.project_options.parts_dir)
def _create_meta(self, step: steps.Step, part_names: Sequence[str]) -> None: if step == steps.PRIME and part_names == self.config.part_names: meta.create_snap_packaging(self.config)