Skip to content

Commit

Permalink
massive cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
manuphatak committed Dec 19, 2015
1 parent f02308b commit 7432b77
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 338 deletions.
7 changes: 5 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ History
Next Release
------------

- Stay Tuned.
- Add support for py26 and py35
- Pin dev dependencies
- Reorganized package
- Updated doc builds

1.2.0 (2015-05-18)
------------------

- Feature: Improved compatibility to PY27, PY32, PY33, PY34, and PYPY
- Feature: Improved compatibility to py27, py32, py33, py34, and pypy
- Feature: Supports multiple config files.
- Feature: Writes less, smarter logic on deciding if a write is necessary.
- Feature: Delegates writes to a background process.
Expand Down
2 changes: 2 additions & 0 deletions json_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
__version__ = '1.2.0'

from .configuration import connect

__all__ = ['connect']
6 changes: 3 additions & 3 deletions json_config/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import json
import threading
from functools import wraps, partial
from collections import defaultdict
from functools import wraps, partial

pprint = True

Expand Down Expand Up @@ -152,11 +152,11 @@ def block(self):
to a file being managed to this tool, use this to make sure the file
safe to read and write on.
"""
save_config_threads = [thread for thread in threading.enumerate() if
thread.name == self._container.config_file]
save_config_threads = [thread for thread in threading.enumerate() if thread.name == self._container.config_file]

for save_config_thread in save_config_threads:
save_config_thread.join()


# export
connect = ConfigObject.connect
34 changes: 0 additions & 34 deletions test/sample_assets/sample_config.json

This file was deleted.

281 changes: 0 additions & 281 deletions test/sample_assets/sample_config_large.json

This file was deleted.

34 changes: 34 additions & 0 deletions tests/sample_assets/sample_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"test": "success",
"cat_1": {
"sub_1": {
"sub_sub_1": {
"sub_sub_sub_1": "sub_sub_sub_1 value",
"sub_sub_sub_2": "sub_sub_sub_2 value"
}
}
},
"cat_2": "cat_2 value",
"cat_3": {
"sub_1": {
"sub_sub_1": "sub_sub_1 value",
"sub_sub_2": {
"sub_sub_sub_1": "sub_sub_sub_1",
"sub_sub_sub_2": "sub_sub_sub_2"
}
}
},
"cat_4": {
"0": {
"cat": "cat value 0"
},
"1": {
"cat": {
"nested_list": "nested_list value"
}
},
"2": {
"cat": "cat value 2"
}
}
}
281 changes: 281 additions & 0 deletions tests/sample_assets/sample_config_large.json

Large diffs are not rendered by default.

34 changes: 16 additions & 18 deletions test/test_configuration.py → tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
Tests for `configuration` module.
"""
import json
from os.path import dirname, join
import shutil
from os.path import dirname, join

from mock import Mock
import pytest
from pytest import fixture, mark, raises

test_dir = dirname(__file__)


@pytest.fixture
@fixture
def sample_config_file(tmpdir):
config_asset = join(test_dir, 'sample_assets', 'sample_config.json')

Expand All @@ -22,26 +22,26 @@ def sample_config_file(tmpdir):
return mock_config


@pytest.fixture
@fixture
def config(sample_config_file):
import json_config

return json_config.connect(sample_config_file)


@pytest.fixture
@fixture
def empty_config_file(tmpdir):
return tmpdir.join('empty_config.json').strpath


@pytest.fixture
@fixture
def empty_config(empty_config_file):
import json_config

return json_config.connect(empty_config_file)


@pytest.fixture
@fixture
def mock_write_file(empty_config):
write_file = empty_config.write_file

Expand All @@ -56,7 +56,7 @@ def test_config_file_fixture(sample_config_file):


def test_config_file(empty_config_file):
with pytest.raises(IOError):
with raises(IOError):
json.load(open(empty_config_file))


Expand All @@ -68,15 +68,15 @@ def test_loads_json_file_returns_dict_like_obj_from_empty(empty_config):
assert empty_config['test'] == {}


@pytest.mark.skipif
@mark.skipif
def test_it_returns_the_length_of_all_items_including_children():
# assert len(config) == 10
pass # TODO


def test_it_can_be_iterated_on(config):
iter_config = list(config)
assert set(iter_config) == {'test', 'cat_1', 'cat_2', 'cat_3', 'cat_4'}
assert set(iter_config) == set(('test', 'cat_1', 'cat_2', 'cat_3', 'cat_4'))


def test_it_uses_dictionary_syntax_for_get(config):
Expand Down Expand Up @@ -133,8 +133,7 @@ def test_it_saves_when_a_value_is_set(config, sample_config_file):
assert expected['not a test'] == 'mildly pass'


def test_it_saves_when_a_value_is_set_from_empty(empty_config,
empty_config_file):
def test_it_saves_when_a_value_is_set_from_empty(empty_config, empty_config_file):
empty_config['not a test'] = 'mildly pass'
empty_config.block()
expected = json.load(open(empty_config_file))
Expand All @@ -150,7 +149,7 @@ def test_it_saves_only_once_when_a_value_is_set(mock_write_file):
assert mock_write_file.write_file.call_count == 1


# @pytest.mark.xfail
# @mark.xfail
def test_it_only_saves_once_when_a_nested_value_is_set(mock_write_file):
assert mock_write_file.write_file.call_count == 0
mock_write_file['cat_4'][0]['test']['1']['2']['3'][0] = 'successful 0'
Expand All @@ -164,8 +163,8 @@ def test_it_saves_when_a_value_is_deleted(config, sample_config_file):

expected = json.load(open(sample_config_file))

with pytest.raises(KeyError):
_ = expected['cat_2']
with raises(KeyError):
_ = expected['cat_2'] # noqa


def test_it_saves_when_a_nested_value_is_set(config, sample_config_file):
Expand All @@ -177,8 +176,7 @@ def test_it_saves_when_a_nested_value_is_set(config, sample_config_file):
assert expected['cat_3']['sub_2'] == 'test_success'


def test_it_saves_when_a_nested_value_is_set_from_empty(empty_config,
empty_config_file):
def test_it_saves_when_a_nested_value_is_set_from_empty(empty_config, empty_config_file):
empty_config['cat_3']['sub_2'] = 'test_success'

assert empty_config['cat_3']['sub_2'] == 'test_success'
Expand Down Expand Up @@ -210,7 +208,7 @@ def test_it_creates_a_new_file(tmpdir):
assert actual == dict(config)


@pytest.mark.skipif
@mark.skipif
def test_it_throws_error_if_nesting_lists_and_dicts():
# TODO
pass
Expand Down

0 comments on commit 7432b77

Please sign in to comment.