class ScriptletMultipleSettersErrorTestCase(unit.TestCase): scriptlet_scenarios = [ ("override-pull", {"override_pull": "snapcraftctl {setter} 1"}), ("override-build", {"override_build": "snapcraftctl {setter} 2"}), ("override-stage", {"override_stage": "snapcraftctl {setter} 3"}), ("override-prime", {"override_prime": "snapcraftctl {setter} 4"}), ] multiple_setters_scenarios = multiply_scenarios( scriptlet_scenarios, scriptlet_scenarios ) setter_scenarios = [ ("set-version", {"setter": "set-version"}), ("set-grade", {"setter": "set-grade"}), ] scenarios = multiply_scenarios(setter_scenarios, multiple_setters_scenarios) def test_set_multiple_times(self): part_properties = {} with contextlib.suppress(AttributeError): part_properties["override-pull"] = self.override_pull.format( setter=self.setter ) with contextlib.suppress(AttributeError): part_properties["override-build"] = self.override_build.format( setter=self.setter ) with contextlib.suppress(AttributeError): part_properties["override-stage"] = self.override_stage.format( setter=self.setter ) with contextlib.suppress(AttributeError): part_properties["override-prime"] = self.override_prime.format( setter=self.setter ) # A few of these test cases result in only one of these scriptlets # being set. In that case, we actually want to double them up (i.e. # call set-version twice in the same scriptlet), which should still be # an error. if len(part_properties) == 1: for key, value in part_properties.items(): part_properties[key] += "\n{}".format(value) handler = self.load_part("test_part", part_properties=part_properties) with testtools.ExpectedException(errors.ScriptletRunError): silent_popen = functools.partial( subprocess.Popen, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) with mock.patch("subprocess.Popen", wraps=silent_popen): handler.pull() handler.build() handler.stage() handler.prime()
class InvalidStopRefreshModesTest(ValidationBaseTest): bad_values = [(mode, dict(mode=mode)) for mode in ["sigterm-bad", "123", "-----"]] keys = [(k, dict(key=k)) for k in ["stop-mode", "refresh-mode"]] scenarios = multiply_scenarios(keys, bad_values) def setUp(self): super().setUp() self.valid_modes = { "stop-mode": ( "['sigterm', 'sigterm-all', 'sighup', 'sighup-all', " "'sigusr1', 'sigusr1-all', 'sigusr2', 'sigusr2-all']" ), "refresh-mode": "['endure', 'restart']", } def test_invalid_modes(self): self.data["apps"] = { "service1": {"command": "binary1", "daemon": "simple", self.key: self.mode} } raised = self.assertRaises( errors.YamlValidationError, Validator(self.data).validate ) expected_message = ( "The 'apps/service1/{}' property does not match the " "required schema: '{}' is not one of {}" ).format(self.key, self.mode, self.valid_modes[self.key]) self.assertThat(raised.message, Equals(expected_message), message=self.data)
class NodePluginManifestTest(NodePluginBaseTest): scenarios = multiply_scenarios( [ ( "simple", dict( ls_output=( '{"dependencies": {' ' "testpackage1": {"version": "1.0"},' ' "testpackage2": {"version": "1.2"}}}' ), expected_dependencies=["testpackage1=1.0", "testpackage2=1.2"], ), ), ( "nested", dict( ls_output=( '{"dependencies": {' ' "testpackage1": {' ' "version": "1.0",' ' "dependencies": {' ' "testpackage2": {"version": "1.2"}}}}}' ), expected_dependencies=["testpackage1=1.0", "testpackage2=1.2"], ), ), ( "missing", dict( ls_output=( '{"dependencies": {' ' "testpackage1": {"version": "1.0"},' ' "testpackage2": {"version": "1.2"},' ' "missing": {"noversion": "dummy"}}}' ), expected_dependencies=["testpackage1=1.0", "testpackage2=1.2"], ), ), ("none", dict(ls_output="{}", expected_dependencies=[])), ], [("npm", dict(package_manager="npm")), ("yarn", dict(package_manager="yarn"))], ) def test_get_manifest_with_node_packages(self): self.run_output_mock.return_value = self.ls_output self.options.node_package_manager = self.package_manager plugin = nodejs.NodePlugin("test-part", self.options, self.project) self.create_assets(plugin) plugin.build() self.assertThat( plugin.get_manifest(), Equals( collections.OrderedDict({"node-packages": self.expected_dependencies}) ), )
class TestReturnCodeToSubunit(ResourcedTestCase): scenarios = multiply_scenarios([ ('readdefault', dict(reader=read_all)), ('readsingle', dict(reader=read_single)), ('readline', dict(reader=readline)), ('readlines', dict(reader=readlines)), ], [('noeol', dict(stdout=_b('foo\nbar'))), ('trailingeol', dict(stdout=_b('foo\nbar\n')))]) def test_returncode_0_no_change(self): proc = ProcessModel(None) proc.stdout.write(self.stdout) proc.stdout.seek(0) stream = run.ReturnCodeToSubunit(proc) content = accumulate(stream, self.reader) self.assertEqual(self.stdout, content) def test_returncode_nonzero_fail_appended_to_content(self): proc = ProcessModel(None) proc.stdout.write(self.stdout) proc.stdout.seek(0) proc.returncode = 1 stream = run.ReturnCodeToSubunit(proc) content = accumulate(stream, self.reader) buffer = BytesIO() buffer.write(b'foo\nbar\n') stream = subunit.StreamResultToBytes(buffer) stream.status(test_id='process-returncode', test_status='fail', file_name='traceback', mime_type='text/plain;charset=utf8', file_bytes=b'returncode 1') expected_content = buffer.getvalue() self.assertEqual(expected_content, content)
def test_multiply_many_scenarios(self): def factory(name): for i in 'abc': yield i, {name: i} scenarios = multiply_scenarios(factory('p'), factory('q'), factory('r'), factory('t')) self.assertEqual(3**4, len(scenarios), scenarios) self.assertEqual('a,a,a,a', scenarios[0][0])
def test_multiply_scenarios(self): def factory(name): for i in 'ab': yield i, {name: i} scenarios = multiply_scenarios(factory('p'), factory('q')) self.assertEqual([ ('a,a', dict(p='a', q='a')), ('a,b', dict(p='a', q='b')), ('b,a', dict(p='b', q='a')), ('b,b', dict(p='b', q='b')), ], scenarios)
def test_multiply_many_scenarios(self): def factory(name): for i in 'abc': yield i, {name: i} scenarios = multiply_scenarios(factory('p'), factory('q'), factory('r'), factory('t')) self.assertEqual( 3**4, len(scenarios), scenarios) self.assertEqual( 'a,a,a,a', scenarios[0][0])
class FloatingIpSameNetwork(FloatingIpTestCasesMixin, base.BaseTempestTestCase): scenarios = multiply_scenarios([ ('SRC with FIP', dict(src_has_fip=True)), ('SRC without FIP', dict(src_has_fip=False)), ], [ ('DEST with FIP', dict(dest_has_fip=True)), ('DEST without FIP', dict(dest_has_fip=False)), ]) same_network = True @decorators.idempotent_id('05c4e3b3-7319-4052-90ad-e8916436c23b') def test_east_west(self): self._test_east_west()
class FloatingIpSeparateNetwork(FloatingIpTestCasesMixin, base.BaseTempestTestCase): scenarios = multiply_scenarios([ ('SRC with FIP', dict(src_has_fip=True)), ('SRC without FIP', dict(src_has_fip=False)), ], [ ('DEST with FIP', dict(dest_has_fip=True)), ('DEST without FIP', dict(dest_has_fip=False)), ]) same_network = False @decorators.idempotent_id('f18f0090-3289-4783-b956-a0f8ac511e8b') def test_east_west(self): self._test_east_west()
class StackStatusActionTest(testtools.TestCase): scenarios = scnrs.multiply_scenarios( [('CREATE', dict(action='CREATE')), ('DELETE', dict(action='DELETE')), ('UPDATE', dict(action='UPDATE')), ('ROLLBACK', dict(action='ROLLBACK')), ('SUSPEND', dict(action='SUSPEND')), ('RESUME', dict(action='RESUME')), ('CHECK', dict(action='CHECK'))], [('IN_PROGRESS', dict(status='IN_PROGRESS')), ('FAILED', dict(status='FAILED')), ('COMPLETE', dict(status='COMPLETE'))]) def test_status_action(self): stack_status = '%s_%s' % (self.action, self.status) stack = mock_stack(None, 'stack_1', 'abcd1234') stack.stack_status = stack_status self.assertEqual(self.action, stack.action) self.assertEqual(self.status, stack.status)
class NodePluginManifestTestCase(NodePluginBaseTestCase): scenarios = multiply_scenarios( [('simple', dict(ls_output=('{"dependencies": {' ' "testpackage1": {"version": "1.0"},' ' "testpackage2": {"version": "1.2"}}}'))), ('nested', dict(ls_output=('{"dependencies": {' ' "testpackage1": {' ' "version": "1.0",' ' "dependencies": {' ' "testpackage2": {"version": "1.2"}}}}}'))), ('missing', dict(ls_output=('{"dependencies": {' ' "testpackage1": {"version": "1.0"},' ' "testpackage2": {"version": "1.2"},' ' "missing": {"noversion": "dummy"}}}')))], [('npm', dict(package_manager='npm')), ('yarn', dict(package_manager='yarn'))]) def test_get_manifest_with_node_packages(self): self.run_output_mock.return_value = self.ls_output self.options.node_package_manager = self.package_manager plugin = nodejs.NodePlugin('test-part', self.options, self.project_options) os.makedirs(plugin.sourcedir) plugin.build() self.assertThat( plugin.get_manifest(), Equals( collections.OrderedDict({ 'node-packages': ['testpackage1=1.0', 'testpackage2=1.2'] })))
class NodePluginTest(NodePluginBaseTest): scenarios = multiply_scenarios( [ ("without-proxy", dict(http_proxy=None, https_proxy=None)), ( "with-proxy", dict( http_proxy="http://*****:*****@org/name") plugin.build() if self.package_manager == "npm": expected_run_calls = [ mock.call( [ self.get_npm_cmd(plugin), "install", "--offline", "--prod" ], cwd=os.path.join(plugin.builddir), env=mock.ANY, ), mock.call( [self.get_npm_cmd(plugin), "pack"], cwd=plugin.builddir, env=mock.ANY, ), mock.call( [ self.get_npm_cmd(plugin), "install", "--offline", "--prod" ], cwd=os.path.join(plugin.builddir, "package"), env=mock.ANY, ), ] else: cmd = [self.get_yarn_cmd(plugin)] if self.http_proxy is not None: cmd.extend(["--proxy", self.http_proxy]) if self.https_proxy is not None: cmd.extend(["--https-proxy", self.https_proxy]) expected_run_calls = [ mock.call( cmd + ["install", "--offline", "--prod"], cwd=plugin.builddir, env=mock.ANY, ), mock.call( cmd + ["pack", "--filename", "org-name-1.0.tgz"], cwd=plugin.builddir, env=mock.ANY, ), mock.call( cmd + ["install", "--offline", "--prod"], cwd=os.path.join(plugin.builddir, "package"), env=mock.ANY, ), ] self.run_mock.assert_has_calls(expected_run_calls) expected_tar_calls = [ mock.call("org-name-1.0.tgz", plugin.builddir), mock.call().provision(os.path.join(plugin.builddir, "package")), ] self.tar_mock.assert_has_calls(expected_tar_calls)
class PluginsTestScenarios(JenkinsPluginsBase): scenarios = multiply_scenarios(JenkinsPluginsBase.scenarios, [ ('s1', dict(v1='1.0.0', op='__gt__', v2='0.8.0')), ('s2', dict(v1='1.0.1alpha', op='__gt__', v2='1.0.0')), ('s3', dict(v1='1.0', op='__eq__', v2='1.0.0')), ('s4', dict(v1='1.0', op='__eq__', v2='1.0')), ('s5', dict(v1='1.0', op='__lt__', v2='1.8.0')), ('s6', dict(v1='1.0.1alpha', op='__lt__', v2='1.0.1')), ('s7', dict(v1='1.0alpha', op='__lt__', v2='1.0.0')), ('s8', dict(v1='1.0-alpha', op='__lt__', v2='1.0.0')), ('s9', dict(v1='1.1-alpha', op='__gt__', v2='1.0')), ('s10', dict(v1='1.0-SNAPSHOT', op='__lt__', v2='1.0')), ('s11', dict(v1='1.0.preview', op='__lt__', v2='1.0')), ('s12', dict(v1='1.1-SNAPSHOT', op='__gt__', v2='1.0')), ('s13', dict(v1='1.0a-SNAPSHOT', op='__lt__', v2='1.0a')), ]) def setUp(self): super(PluginsTestScenarios, self).setUp() plugin_info_json = dict(self.plugin_info_json) plugin_info_json[u"plugins"][0][u"version"] = self.v1 patcher = patch.object(jenkins.Jenkins, 'jenkins_open') self.jenkins_mock = patcher.start() self.addCleanup(patcher.stop) self.jenkins_mock.return_value = json.dumps(plugin_info_json) def test_plugin_version_comparison(self): """Verify that valid versions are ordinally correct. That is, for each given scenario, v1.op(v2)==True where 'op' is the equality operator defined for the scenario. """ plugin_name = "Jenkins Mailer Plugin" j = jenkins.Jenkins(self.base_url, 'test', 'test') plugin_info = j.get_plugins()[plugin_name] v1 = plugin_info.get("version") op = getattr(v1, self.op) self.assertTrue(op(self.v2), msg="Unexpectedly found {0} {2} {1} == False " "when comparing versions!".format( v1, self.v2, self.op)) def test_plugin_version_object_comparison(self): """Verify use of PluginVersion for comparison Verify that converting the version to be compared to the same object type of PluginVersion before comparing provides the same result. """ plugin_name = "Jenkins Mailer Plugin" j = jenkins.Jenkins(self.base_url, 'test', 'test') plugin_info = j.get_plugins()[plugin_name] v1 = plugin_info.get("version") op = getattr(v1, self.op) v2 = plugins.PluginVersion(self.v2) self.assertTrue(op(v2), msg="Unexpectedly found {0} {2} {1} == False " "when comparing versions!".format(v1, v2, self.op))
class TestScriptletMultipleSettersError: scriptlet_scenarios = [ ( "override-pull/build", { "override_pull": "snapcraftctl {setter} {value}", "override_build": "snapcraftctl {setter} {value}", "override_stage": None, "override_prime": None, }, ), ( "override-pull/stage", { "override_pull": "snapcraftctl {setter} {value}", "override_build": None, "override_stage": "snapcraftctl {setter} {value}", "override_prime": None, }, ), ( "override-pull/prime", { "override_pull": "snapcraftctl {setter} {value}", "override_build": None, "override_stage": None, "override_prime": "snapcraftctl {setter} {value}", }, ), ( "override-build/stage", { "override_pull": None, "override_build": "snapcraftctl {setter} {value}", "override_stage": "snapcraftctl {setter} {value}", "override_prime": None, }, ), ( "override-build/prime", { "override_pull": None, "override_build": "snapcraftctl {setter} {value}", "override_stage": None, "override_prime": "snapcraftctl {setter} {value}", }, ), ( "override-stage/prime", { "override_pull": None, "override_build": None, "override_stage": "snapcraftctl {setter} {value}", "override_prime": "snapcraftctl {setter} {value}", }, ), ] setter_scenarios = [ ("set-version", { "setter": "set-version", "value": "v1" }), ("set-grade", { "setter": "set-grade", "value": "stable" }), ] scenarios = multiply_scenarios(setter_scenarios, scriptlet_scenarios) def test_set_multiple_times( self, tmp_work_path, setter, value, override_pull, override_build, override_stage, override_prime, ): part_properties = {} if override_pull is not None: part_properties["override-pull"] = override_pull.format( setter=setter, value=value) if override_build is not None: part_properties["override-build"] = override_build.format( setter=setter, value=value) if override_stage is not None: part_properties["override-stage"] = override_stage.format( setter=setter, value=value) if override_prime is not None: part_properties["override-prime"] = override_prime.format( setter=setter, value=value) # A few of these test cases result in only one of these scriptlets # being set. In that case, we actually want to double them up (i.e. # call set-version twice in the same scriptlet), which should still be # an error. if len(part_properties) == 1: for key, value in part_properties.items(): part_properties[key] += "\n{}".format(value) handler = unit.load_part("test_part", part_properties=part_properties) with testtools.ExpectedException(errors.ScriptletDuplicateFieldError): silent_popen = functools.partial(subprocess.Popen, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) with mock.patch("subprocess.Popen", wraps=silent_popen): handler.pull() handler.build() handler.stage() handler.prime()
class TestValidArchitectures: yaml_scenarios = [ ( "none", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": None, }, ), ( "single string list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": "[amd64]", }, ), ( "multiple string list", { "expected_amd64": ["amd64", "i386"], "expected_i386": ["amd64", "i386"], "expected_armhf": ["armhf"], "yaml": "[amd64, i386]", }, ), ( "single object list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent(""" - build-on: [amd64] run-on: [amd64] """), }, ), ( "multiple object list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf", "arm64"], "yaml": dedent(""" - build-on: [amd64] run-on: [amd64] - build-on: [i386] run-on: [i386] - build-on: [armhf] run-on: [armhf, arm64] """), }, ), ( "omit run-on", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent(""" - build-on: [amd64] """), }, ), ( "single build-on string, no list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent(""" - build-on: amd64 """), }, ), ( "build- and run-on string, no lists", { "expected_amd64": ["amd64"], "expected_i386": ["amd64"], "expected_armhf": ["armhf"], "yaml": dedent(""" - build-on: i386 run-on: amd64 """), }, ), ( "build on all", { "expected_amd64": ["amd64"], "expected_i386": ["amd64"], "expected_armhf": ["amd64"], "yaml": dedent(""" - build-on: [all] run-on: [amd64] """), }, ), ( "run on all", { "expected_amd64": ["all"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent(""" - build-on: [amd64] run-on: [all] """), }, ), ] arch_scenarios = [ ("amd64", { "target_arch": "amd64" }), ("i386", { "target_arch": "i386" }), ("armhf", { "target_arch": "armhf" }), ] scenarios = multiply_scenarios(yaml_scenarios, arch_scenarios) def test( self, tmp_work_path, yaml, target_arch, expected_amd64, expected_i386, expected_armhf, ): snippet = "architectures: {}".format(yaml) if yaml else "" snapcraft_yaml = dedent("""\ name: test base: core18 version: "1" summary: test description: test {} parts: my-part: plugin: nil """).format(snippet) c = get_project_config(snapcraft_yaml, target_deb_arch=target_arch) expected_targets = { "amd64": expected_amd64, "i386": expected_i386, "armhf": expected_armhf, } assert c.data["architectures"] == expected_targets[target_arch]
class NodePluginTestCase(NodePluginBaseTestCase): scenarios = multiply_scenarios( [ ("without-proxy", dict(http_proxy=None, https_proxy=None)), ( "with-proxy", dict( http_proxy="http://*****:*****@mock.patch("snapcraft.ProjectOptions.deb_arch", "fantasy-arch") def test_unsupported_arch_raises_exception(self): self.options.node_package_manager = self.package_manager raised = self.assertRaises( errors.SnapcraftEnvironmentError, nodejs.NodePlugin, "test-part", self.options, self.project_options, ) self.assertThat(raised.__str__(), Equals("architecture not supported (fantasy-arch)")) def test_get_build_properties(self): expected_build_properties = ["node-packages", "npm-run", "npm-flags"] resulting_build_properties = nodejs.NodePlugin.get_build_properties() self.assertThat(resulting_build_properties, HasLength(len(expected_build_properties))) for property in expected_build_properties: self.assertIn(property, resulting_build_properties) def test_get_pull_properties(self): expected_pull_properties = ["node-engine", "node-package-manager"] resulting_pull_properties = nodejs.NodePlugin.get_pull_properties() self.assertThat(resulting_pull_properties, HasLength(len(expected_pull_properties))) for property in expected_pull_properties: self.assertIn(property, resulting_pull_properties) def test_clean_pull_step(self): self.options.node_package_manager = self.package_manager plugin = nodejs.NodePlugin("test-part", self.options, self.project_options) os.makedirs(plugin.sourcedir) plugin.pull() self.assertTrue(os.path.exists(plugin._npm_dir)) plugin.clean_pull() self.assertFalse(os.path.exists(plugin._npm_dir))
class NodePluginTestCase(NodePluginBaseTestCase): scenarios = multiply_scenarios( [('without-proxy', dict(http_proxy=None, https_proxy=None)), ('with-proxy', dict(http_proxy='http://*****:*****@mock.patch('snapcraft.ProjectOptions.deb_arch', 'fantasy-arch') def test_unsupported_arch_raises_exception(self): self.options.node_package_manager = self.package_manager raised = self.assertRaises(errors.SnapcraftEnvironmentError, nodejs.NodePlugin, 'test-part', self.options, self.project_options) self.assertThat(raised.__str__(), Equals('architecture not supported (fantasy-arch)')) def test_get_build_properties(self): expected_build_properties = ['node-packages', 'npm-run'] resulting_build_properties = nodejs.NodePlugin.get_build_properties() self.assertThat(resulting_build_properties, HasLength(len(expected_build_properties))) for property in expected_build_properties: self.assertIn(property, resulting_build_properties) def test_get_pull_properties(self): expected_pull_properties = ['node-engine', 'node-package-manager'] resulting_pull_properties = nodejs.NodePlugin.get_pull_properties() self.assertThat(resulting_pull_properties, HasLength(len(expected_pull_properties))) for property in expected_pull_properties: self.assertIn(property, resulting_pull_properties) def test_clean_pull_step(self): self.options.node_package_manager = self.package_manager plugin = nodejs.NodePlugin('test-part', self.options, self.project_options) os.makedirs(plugin.sourcedir) plugin.pull() self.assertTrue(os.path.exists(plugin._npm_dir)) plugin.clean_pull() self.assertFalse(os.path.exists(plugin._npm_dir))
#!/usr/bin/env python # coding=utf-8 from testscenarios.scenarios import multiply_scenarios scenarios = multiply_scenarios( [('scenario1', dict(param1=1)), ('scenario2', dict(param1=2))], [('scenario2', dict(param2=1))], )
class ValidArchitecturesTest(ProjectLoaderBaseTest): yaml_scenarios = [ ( "none", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": None, }, ), ( "single string list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": "[amd64]", }, ), ( "multiple string list", { "expected_amd64": ["amd64", "i386"], "expected_i386": ["amd64", "i386"], "expected_armhf": ["armhf"], "yaml": "[amd64, i386]", }, ), ( "single object list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent( """ - build-on: [amd64] run-on: [amd64] """ ), }, ), ( "multiple object list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf", "arm64"], "yaml": dedent( """ - build-on: [amd64] run-on: [amd64] - build-on: [i386] run-on: [i386] - build-on: [armhf] run-on: [armhf, arm64] """ ), }, ), ( "omit run-on", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent( """ - build-on: [amd64] """ ), }, ), ( "single build-on string, no list", { "expected_amd64": ["amd64"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent( """ - build-on: amd64 """ ), }, ), ( "build- and run-on string, no lists", { "expected_amd64": ["amd64"], "expected_i386": ["amd64"], "expected_armhf": ["armhf"], "yaml": dedent( """ - build-on: i386 run-on: amd64 """ ), }, ), ( "build on all", { "expected_amd64": ["amd64"], "expected_i386": ["amd64"], "expected_armhf": ["amd64"], "yaml": dedent( """ - build-on: [all] run-on: [amd64] """ ), }, ), ( "run on all", { "expected_amd64": ["all"], "expected_i386": ["i386"], "expected_armhf": ["armhf"], "yaml": dedent( """ - build-on: [amd64] run-on: [all] """ ), }, ), ] arch_scenarios = [ ("amd64", {"target_arch": "amd64"}), ("i386", {"target_arch": "i386"}), ("armhf", {"target_arch": "armhf"}), ] scenarios = multiply_scenarios(yaml_scenarios, arch_scenarios) def test_architectures(self): snippet = "" if self.yaml: snippet = "architectures: {}".format(self.yaml) snapcraft_yaml = dedent( """\ name: test base: core18 version: "1" summary: test description: test {} parts: my-part: plugin: nil """ ).format(snippet) try: project_kwargs = dict(target_deb_arch=self.target_arch) c = self.make_snapcraft_project(snapcraft_yaml, project_kwargs) expected = getattr(self, "expected_{}".format(self.target_arch)) self.assertThat(c.data["architectures"], Equals(expected)) except errors.YamlValidationError as e: self.fail("Expected YAML to be valid, got an error: {}".format(e))
#!/usr/bin/env python # coding=utf-8 from testscenarios.scenarios import multiply_scenarios scenarios = multiply_scenarios([('scenario1', dict(param1=1)), ('scenario2', dict(param1=2))], [('scenario2', dict(param2=1))],)