From 4e8c1621c49dac503a790cd46f843135342ae618 Mon Sep 17 00:00:00 2001 From: Francois Dang Ngoc Date: Sun, 12 Apr 2015 14:08:26 -0400 Subject: [PATCH] added more unit tests --- samples/aws.conf | 9 +++++++++ tests/test_config_parser.py | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 samples/aws.conf diff --git a/samples/aws.conf b/samples/aws.conf new file mode 100644 index 00000000..9698efeb --- /dev/null +++ b/samples/aws.conf @@ -0,0 +1,9 @@ +{ + // dict merge + data-center-generic = { cluster-size = 6 } + data-center-east = ${data-center-generic} { name = "east" } + + // list merge + default-jvm-opts = [-XX:+UseParNewGC] + large-jvm-opts = ${default-jvm-opts} [-Xm16g] +} diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index d7bdb1da..be865ba6 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -280,6 +280,19 @@ def test_dict_substitutions(self): assert config3.get('data-center-east.name') == 'east' assert config3.get('data-center-east.opts') == '-Xmx4g' + config4 = ConfigFactory.parse_string( + """ + data-center-generic = { cluster-size = 6 } + data-center-east = {name = "east"} ${data-center-generic} + data-center-east-prod = ${data-center-east} {tmpDir=/tmp} + """ + ) + + assert config4.get('data-center-east.cluster-size') == 6 + assert config4.get('data-center-east.name') == 'east' + assert config4.get('data-center-east-prod.cluster-size') == 6 + assert config4.get('data-center-east-prod.tmpDir') == '/tmp' + def test_list_substitutions(self): config = ConfigFactory.parse_string( """ @@ -306,8 +319,21 @@ def test_list_substitutions(self): """ ) + assert config3.get('common_modules') == ['php', 'python'] assert config3.get('host_modules') == ['java', 'php', 'python', 'perl'] + config4 = ConfigFactory.parse_string( + """ + common_modules = [php, python] + host_modules = [java] ${common_modules} [perl] + full_modules = ${host_modules} [c, go] + """ + ) + + assert config4.get('common_modules') == ['php', 'python'] + assert config4.get('host_modules') == ['java', 'php', 'python', 'perl'] + assert config4.get('full_modules') == ['java', 'php', 'python', 'perl', 'c', 'go'] + def test_include_dict(self): config = ConfigFactory.parse_file("samples/animals.conf") assert config.get('cat.garfield.say') == 'meow'