From 56d783f612e03bc4bc570112fc9711953c5c2ffa Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 17 Nov 2011 13:03:56 +0100 Subject: [PATCH 1/2] tests and fixtures for type parameters with dashes Signed-off-by: Steven Armstrong --- lib/cdist/test/emulator/__init__.py | 39 +++++++++++++++++++ .../parameter/required | 1 + 2 files changed, 40 insertions(+) create mode 100644 lib/cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required diff --git a/lib/cdist/test/emulator/__init__.py b/lib/cdist/test/emulator/__init__.py index 8f1b9776..5c920770 100644 --- a/lib/cdist/test/emulator/__init__.py +++ b/lib/cdist/test/emulator/__init__.py @@ -88,3 +88,42 @@ class EmulatorTestCase(test.CdistTestCase): emu = emulator.Emulator(argv) emu.run() # if we get here all is fine + + +import os.path as op +my_dir = op.abspath(op.dirname(__file__)) +fixtures = op.join(my_dir, 'fixtures') + +class ArgumentsWithDashesTestCase(test.CdistTestCase): + + def setUp(self): + self.temp_dir = self.mkdtemp() + self.target_host = 'localhost' + out_path = self.temp_dir + handle, self.script = self.mkstemp(dir=self.temp_dir) + os.close(handle) + _local_base_path = fixtures + self.local = local.Local(self.target_host, _local_base_path, out_path) + self.local.create_directories() + self.local.link_emulator(test.cdist_exec_path) + self.env = { + 'PATH': "%s:%s" % (self.local.bin_path, os.environ['PATH']), + '__target_host': self.target_host, + '__global': self.local.out_path, + '__cdist_type_base_path': self.local.type_path, # for use in type emulator + '__manifest': self.local.manifest_path, + '__cdist_manifest': self.script, + } + + def tearDown(self): + shutil.rmtree(self.temp_dir) + + def test_arguments_with_dashes(self): + argv = ['__arguments_with_dashes', 'some-id', '--with-dash', 'some value'] + os.environ.update(self.env) + emu = emulator.Emulator(argv) + emu.run() + + cdist_type = core.Type(self.local.type_path, '__arguments_with_dashes') + cdist_object = core.Object(cdist_type, self.local.object_path, 'some-id') + self.assertTrue('with-dash' in cdist_object.parameters) diff --git a/lib/cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required new file mode 100644 index 00000000..02fabce1 --- /dev/null +++ b/lib/cdist/test/emulator/fixtures/conf/type/__arguments_with_dashes/parameter/required @@ -0,0 +1 @@ +with-dash From 68f66af21a2ed23f36d926dde0e7d24e54bc7346 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 17 Nov 2011 13:04:39 +0100 Subject: [PATCH 2/2] implement: accept parameters with dashes Signed-off-by: Steven Armstrong --- lib/cdist/emulator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cdist/emulator.py b/lib/cdist/emulator.py index 7ae89294..8fd03d4d 100644 --- a/lib/cdist/emulator.py +++ b/lib/cdist/emulator.py @@ -97,10 +97,10 @@ class Emulator(object): for parameter in self.cdist_type.optional_parameters: argument = "--" + parameter - parser.add_argument(argument, action='store', required=False) + parser.add_argument(argument, dest=parameter, action='store', required=False) for parameter in self.cdist_type.required_parameters: argument = "--" + parameter - parser.add_argument(argument, action='store', required=True) + parser.add_argument(argument, dest=parameter, action='store', required=True) # If not singleton support one positional parameter if not self.cdist_type.is_singleton: