-
Notifications
You must be signed in to change notification settings - Fork 4
Support for string indexing in .NET #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2378aa8
031699e
3851cbf
1b0b2e2
5246778
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import unittest | ||
| import json | ||
| import os.path | ||
| from centroid import Config | ||
|
|
||
| class ConfigTest(unittest.TestCase): | ||
|
|
@@ -14,7 +15,7 @@ def _json_config_with_array(self): | |
|
|
||
| @property | ||
| def _shared_file_path(self): | ||
| return 'config.json' | ||
| return os.path.normpath('../config.json') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably roll this back, since the rakefile calls the test from the root directory instead of the test directory. |
||
|
|
||
| def test_create_from_string(self): | ||
| config = Config(self._json_config) | ||
|
|
@@ -132,3 +133,10 @@ def test_has_key(self): | |
| config = Config(self._json_config) | ||
| self.assertTrue("the_environment" in config) | ||
| self.assertTrue("does_not_exist" not in config) | ||
|
|
||
| def test_key_as_index(self): | ||
| config = Config(self._json_config) | ||
| my_string = "thekey" | ||
| self.assertEqual(config.the_environment[my_string], "TheValue") | ||
|
|
||
| unittest.main() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like I should remove unittest.main() as I was running python without the |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ def json_config_with_array | |
| end | ||
|
|
||
| def shared_file_path | ||
| 'config.json' | ||
| File.join('..','..','config.json') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably roll this back, since the rakefile calls the test from the root directory instead of the test directory. |
||
| end | ||
|
|
||
| def test_create_from_string | ||
|
|
@@ -95,35 +95,6 @@ def test_environment_specific_config_overrides_all | |
| assert_equal(config.shared, "production!") | ||
| end | ||
|
|
||
| def test_all_environment_is_not_case_sensitive | ||
| config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "All": {"Shared": "none", "AllOnly": "works"}}') | ||
| config = config.for_environment("Prod") | ||
| assert_equal(config.all_only, "works") | ||
|
|
||
| config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "all": {"Shared": "none", "AllOnly": "works"}}') | ||
| config = config.for_environment("Prod") | ||
| assert_equal(config.all_only, "works") | ||
| end | ||
|
|
||
| def test_supports_deep_merge | ||
| config = Centroid::Config.new('{"Prod": {"Database": {"Server": "prod-sql"}}, "All": {"Database": {"MigrationsPath": "path/to/migrations"}}}') | ||
| config = config.for_environment("Prod") | ||
| assert_equal(config.database.server, "prod-sql") | ||
| assert_equal(config.database.migrations_path, "path/to/migrations") | ||
| end | ||
|
|
||
| def test_has_key | ||
| config = Centroid::Config.new(json_config) | ||
| assert(config.has_key?("the_environment")) | ||
| assert(!config.has_key?("does_not_exist")) | ||
| end | ||
|
|
||
| def test_respond_to | ||
| config = Centroid::Config.new(json_config) | ||
| assert(config.respond_to?(:the_environment)) | ||
| assert(!config.respond_to?(:does_not_exist)) | ||
| end | ||
|
|
||
| def test_indexing_json_array | ||
| config = Centroid::Config.new(json_config_with_array) | ||
| assert_equal(config.the_array[0].the_key, "Value1") | ||
|
|
@@ -169,4 +140,40 @@ def test_enumerated_json_object_values_are_still_shiny | |
| assert_equal(v.password, "secret") | ||
| end | ||
| end | ||
|
|
||
| def test_all_environment_is_not_case_sensitive | ||
| config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "All": {"Shared": "none", "AllOnly": "works"}}') | ||
| config = config.for_environment("Prod") | ||
| assert_equal(config.all_only, "works") | ||
|
|
||
| config = Centroid::Config.new('{"Prod": {"Shared": "production!"}, "all": {"Shared": "none", "AllOnly": "works"}}') | ||
| config = config.for_environment("Prod") | ||
| assert_equal(config.all_only, "works") | ||
| end | ||
|
|
||
| def test_supports_deep_merge | ||
| config = Centroid::Config.new('{"Prod": {"Database": {"Server": "prod-sql"}}, "All": {"Database": {"MigrationsPath": "path/to/migrations"}}}') | ||
| config = config.for_environment("Prod") | ||
| assert_equal(config.database.server, "prod-sql") | ||
| assert_equal(config.database.migrations_path, "path/to/migrations") | ||
| end | ||
|
|
||
| def test_has_key | ||
| config = Centroid::Config.new(json_config) | ||
| assert(config.has_key?("the_environment")) | ||
| assert(!config.has_key?("does_not_exist")) | ||
| end | ||
|
|
||
| def test_key_as_index | ||
| config = Centroid::Config.new(json_config) | ||
| my_string = "thekey" | ||
| assert_equal(config.the_environment[my_string], "TheValue") | ||
| end | ||
|
|
||
| def test_respond_to | ||
| config = Centroid::Config.new(json_config) | ||
| assert(config.respond_to?(:the_environment)) | ||
| assert(!config.respond_to?(:does_not_exist)) | ||
| end | ||
|
|
||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
objectthe right return type here? You'd have to do some kind of type manipulation with the result, which would make it less fluent...Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this returns an
objectis to mimicthis[int index].