Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Align mapper terms #117

Merged
merged 2 commits into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Removed the ability to check for existing files in `sync()`.
- Renamed and consolidated custom exceptions.
- Renamed sync parameter `auto=True` to `auto_save=True`.
- Renamed sync parameter `strict=True` to `auto_attr=False`.
- Renamed sync parameter `strict=True` to `auto_track=False`.
- Added sync parameter `auto_create` to defer file creation to ORM functions.

## 0.7.2 (2016/03/30)
Expand Down
18 changes: 9 additions & 9 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __repr__(self):
return "<auto save off {}>".format(id(self))


@yorm.sync("sample.yml", auto_attr=True)
@yorm.sync("sample.yml", auto_track=True)
class SampleEmptyDecorated:
"""Sample class using standard attribute types."""

Expand Down Expand Up @@ -159,7 +159,7 @@ class StatusDictionary(Dictionary):
pass

def test_decorator(self, tmpdir):
"""Verify standard attribute types dump/load correctly (decorator)."""
"""Verify standard attribute types dump/parse correctly (decorator)."""
tmpdir.chdir()
sample = SampleStandardDecorated('sample')
assert "path/to/default/sample.yml" == sample.__mapper__.path
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_decorator(self, tmpdir):
assert False is sample.falsey

def test_function(self, tmpdir):
"""Verify standard attribute types dump/load correctly (function)."""
"""Verify standard attribute types dump/parse correctly (function)."""
tmpdir.chdir()
_sample = SampleStandard()
attrs = {'object': self.StatusDictionary,
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_function(self, tmpdir):
""") == sample.__mapper__.text

def test_function_to_json(self, tmpdir):
"""Verify standard attribute types dump/load correctly (function)."""
"""Verify standard attribute types dump/parse correctly (function)."""
tmpdir.chdir()
_sample = SampleStandard()
attrs = {'object': self.StatusDictionary,
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_auto_off(self, tmpdir):
sample.string = "hello"
assert "" == sample.__mapper__.text

sample.__mapper__.auto_store = True
sample.__mapper__.auto_save = True
sample.string = "world"

assert strip("""
Expand All @@ -343,7 +343,7 @@ def test_nesting(self, tmpdir):
_sample = SampleNested()
attrs = {'count': Integer,
'results': StatusDictionaryList}
sample = yorm.sync(_sample, "sample.yml", attrs, auto_attr=True)
sample = yorm.sync(_sample, "sample.yml", attrs, auto_track=True)

# check defaults
assert 0 == sample.count
Expand Down Expand Up @@ -405,7 +405,7 @@ def test_objects(self, tmpdir):
""")

# (a mapped attribute must be read first to trigger retrieving)
sample.__mapper__.fetch()
sample.__mapper__.load()

# check object values
assert {'key': 'value'} == sample.object
Expand All @@ -420,7 +420,7 @@ class TestExtended:
"""Integration tests for extended attribute types."""

def test_function(self, tmpdir):
"""Verify extended attribute types dump/load correctly."""
"""Verify extended attribute types dump/parse correctly."""
tmpdir.chdir()
_sample = SampleExtended()
attrs = {'text': Markdown}
Expand Down Expand Up @@ -460,7 +460,7 @@ class TestCustom:
"""Integration tests for custom attribute types."""

def test_decorator(self, tmpdir):
"""Verify custom attribute types dump/load correctly."""
"""Verify custom attribute types dump/parse correctly."""
tmpdir.chdir()
sample = SampleCustomDecorated('sample')

Expand Down
6 changes: 3 additions & 3 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __repr__(self):
class TestCreate:
"""Integration tests for creating mapped classes."""

def test_fetch_from_existing(self, tmpdir):
def test_load_from_existing(self, tmpdir):
"""Verify attributes are updated from an existing file."""
tmpdir.chdir()
sample = SampleStandardDecorated('sample')
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_multiple(self, tmpdir):
class TestUpdate:
"""Integration tests for updating files/object."""

def test_automatic_store_after_first_modification(self, tmpdir):
def test_automatic_save_after_first_modification(self, tmpdir):
tmpdir.chdir()
sample = SampleStandardDecorated('sample')
assert "number_int: 0\n" in sample.__mapper__.text
Expand All @@ -131,7 +131,7 @@ def test_automatic_store_after_first_modification(self, tmpdir):
assert 1 is sample.number_int
assert "number_int: 1\n" in sample.__mapper__.text

def test_automatic_store_after_first_modification_on_list(self, tmpdir):
def test_automatic_save_after_first_modification_on_list(self, tmpdir):
tmpdir.chdir()
sample = SampleStandardDecorated('sample')
assert "array: []\n" in sample.__mapper__.text
Expand Down
3 changes: 2 additions & 1 deletion tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def test_from_top_decorators():


def test_from_top_utilities():
from yorm import new
from yorm import create
from yorm import find
from yorm import find_all
from yorm import load
from yorm import save
from yorm import delete
Expand Down
20 changes: 10 additions & 10 deletions tests/test_nested_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __repr__(self):
@patch('yorm.settings.fake', True)
class TestNestedOnce:

def test_append_triggers_store(self):
def test_append_triggers_save(self):
top = Top()
logging.info("Appending dictionary to list...")
top.nested_list.append({'number': 1})
Expand All @@ -108,7 +108,7 @@ def test_append_triggers_store(self):
number: 1.0
""") == top.__mapper__.text

def test_set_by_index_triggers_store(self):
def test_set_by_index_triggers_save(self):
top = Top()
top.nested_list = [{'number': 1.5}]
assert strip("""
Expand All @@ -133,15 +133,15 @@ def test_set_by_index_triggers_store(self):
number: 1.6
""") == top.__mapper__.text

def test_get_by_index_triggers_fetch(self):
def test_get_by_index_triggers_load(self):
top = Top()
top.__mapper__.text = strip("""
nested_list:
- number: 1.7
""")
assert 1.7 == top.nested_list[0].number

def test_delete_index_triggers_store(self):
def test_delete_index_triggers_save(self):
top = Top()
top.nested_list = [{'number': 1.8}, {'number': 1.9}]
assert strip("""
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_delete_index_triggers_store(self):
number: 1.9
""") == top.__mapper__.text

def test_set_dict_as_attribute_triggers_store(self):
def test_set_dict_as_attribute_triggers_save(self):
top = Top()
top.nested_dict.number = 2
assert strip("""
Expand All @@ -184,7 +184,7 @@ def test_set_dict_as_attribute_triggers_store(self):
@patch('yorm.settings.fake', True)
class TestNestedTwice:

def test_nested_list_item_value_change_triggers_store(self):
def test_nested_list_item_value_change_triggers_save(self):
top = Top()
top.nested_list = [{'number': 3}]
assert strip("""
Expand All @@ -209,7 +209,7 @@ def test_nested_list_item_value_change_triggers_store(self):
number: 4.0
""") == top.__mapper__.text

def test_nested_dict_item_value_change_triggers_store(self):
def test_nested_dict_item_value_change_triggers_save(self):
top = Top()
top.nested_dict = {'nested_list_2': [5]}
assert strip("""
Expand All @@ -229,7 +229,7 @@ def test_nested_dict_item_value_change_triggers_store(self):
nested_list: []
""") == top.__mapper__.text

def test_dict_in_list_value_change_triggers_store(self):
def test_dict_in_list_value_change_triggers_save(self):
top = Top()
top.nested_list.append(None)
top.nested_list[0].nested_dict_3.number = 8
Expand All @@ -244,7 +244,7 @@ def test_dict_in_list_value_change_triggers_store(self):
number: 0.0
""") == top.__mapper__.text

def test_list_in_dict_append_triggers_store(self):
def test_list_in_dict_append_triggers_save(self):
top = Top()
top.nested_list.append(None)
top.nested_list.append(None)
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_alias_list_in_dict(self):
top = Top()
logging.info("Updating nested attribute...")
top.nested_dict.number = 1
logging.info("Storing refs...")
logging.info("Grabbing refs...")
ref1 = top.nested_dict
ref2 = top.nested_dict.nested_list_2
assert id(ref1) == id(top.nested_dict)
Expand Down
4 changes: 2 additions & 2 deletions yorm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

__project__ = 'YORM'
__version__ = '0.8.dev2'
__version__ = '0.8.dev3'

VERSION = __project__ + '-' + __version__

Expand All @@ -17,7 +17,7 @@
from . import bases, types
from .common import UUID
from .decorators import sync, sync_object, sync_instances, attr
from .utilities import new, find, load, save, delete
from .utilities import create, find, find_all, load, save, delete
from .bases import Container, Converter, Mappable, Convertible
except ImportError: # pragma: no cover (manual test)
pass
8 changes: 4 additions & 4 deletions yorm/bases/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create_default(cls):

@abstractclassmethod
def to_value(cls, data):
"""Convert loaded data to an attribute's value."""
"""Convert parsed data to an attribute's value."""
raise NotImplementedError(common.OVERRIDE_MESSAGE)

@abstractclassmethod
Expand All @@ -38,12 +38,12 @@ def create_default(cls):
@classmethod
def to_value(cls, data):
value = cls.create_default()
value.update_value(data, auto_attr=True)
value.update_value(data, auto_track=True)
return value

@abstractmethod
def update_value(self, data, *, auto_attr): # pragma: no cover (abstract method)
"""Update the attribute's value from loaded data."""
def update_value(self, data, *, auto_track): # pragma: no cover (abstract method)
"""Update the attribute's value from parsed data."""
raise NotImplementedError(common.OVERRIDE_MESSAGE)

def format_data(self):
Expand Down
44 changes: 22 additions & 22 deletions yorm/bases/mappable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
TAG = '_modified_by_yorm'


def fetch_before(method):
"""Decorator for methods that should fetch before call."""
def load_before(method):
"""Decorator for methods that should load before call."""

if getattr(method, TAG, False):
return method
Expand All @@ -23,10 +23,10 @@ def wrapped(self, *args, **kwargs):
if not _private_call(method, args):
mapper = common.get_mapper(self)
if mapper and mapper.modified:
log.debug("Fetching before call: %s", method.__name__)
mapper.fetch()
if mapper.auto_store_after_fetch:
mapper.store()
log.debug("Loading before call: %s", method.__name__)
mapper.load()
if mapper.auto_save_after_load:
mapper.save()
mapper.modified = False

return method(self, *args, **kwargs)
Expand All @@ -36,8 +36,8 @@ def wrapped(self, *args, **kwargs):
return wrapped


def store_after(method):
"""Decorator for methods that should store after call."""
def save_after(method):
"""Decorator for methods that should save after call."""

if getattr(method, TAG, False):
return method
Expand All @@ -49,9 +49,9 @@ def wrapped(self, *args, **kwargs):

if not _private_call(method, args):
mapper = common.get_mapper(self)
if mapper and mapper.auto_store:
log.debug("Storing after call: %s", method.__name__)
mapper.store()
if mapper and mapper.auto_save:
log.debug("Saving after call: %s", method.__name__)
mapper.save()

return result

Expand All @@ -75,37 +75,37 @@ class Mappable(metaclass=abc.ABCMeta):

# pylint: disable=no-member

@fetch_before
@load_before
def __getattribute__(self, name):
"""Trigger object update when reading attributes."""
return object.__getattribute__(self, name)

@store_after
@save_after
def __setattr__(self, name, value):
"""Trigger file update when setting attributes."""
super().__setattr__(name, value)

@fetch_before
@load_before
def __iter__(self):
"""Trigger object update when iterating."""
return super().__iter__()

@fetch_before
@load_before
def __getitem__(self, key):
"""Trigger object update when reading an index."""
return super().__getitem__(key)

@store_after
@save_after
def __setitem__(self, key, value):
"""Trigger file update when setting an index."""
super().__setitem__(key, value)

@store_after
@save_after
def __delitem__(self, key):
"""Trigger file update when deleting an index."""
super().__delitem__(key)

@store_after
@save_after
def append(self, value):
"""Trigger file update when appending items."""
super().append(value)
Expand All @@ -122,16 +122,16 @@ def patch_methods(instance):
except AttributeError:
log.trace("No method: %s", name)
else:
modified_method = fetch_before(method)
modified_method = load_before(method)
setattr(cls, name, modified_method)
log.trace("Patched to fetch before call: %s", name)
log.trace("Patched to load before call: %s", name)

for name in ['__setattr__', '__setitem__', '__delitem__', 'append']:
try:
method = getattr(cls, name)
except AttributeError:
log.trace("No method: %s", name)
else:
modified_method = store_after(method)
modified_method = save_after(method)
setattr(cls, name, modified_method)
log.trace("Patched to store after call: %s", name)
log.trace("Patched to save after call: %s", name)