Skip to content
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

Property attributes are enclosed in single underscores instead of dou… #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pypher/builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import re
import sys
import uuid

Expand Down Expand Up @@ -322,8 +323,13 @@ def bind_param(self, value, name=None):
def __getattr__(self, attr):
attr_low = attr.lower()

if attr_low[:2] == '__' and attr_low[-2:] == '__':
link = Property(name=attr.strip('__'))
if re.match('^__[a-z0-9]+__$', attr_low):
try:
self.__dict__.get(attr)
except KeyError:
raise AttributeError(f"'{self.__class__.__name__}' object has not attribute '{attr}'")
elif re.match('^_[a-z0-9]+_$', attr_low):
link = Property(name=attr.strip('_'))
elif attr_low in _LINKS:
link = _LINKS[attr_low]()
else:
Expand Down
8 changes: 4 additions & 4 deletions pypher/test/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_can_add_one_property(self):

def test_can_add_one_property_underscore(self):
p = Pypher()
p.__property__
p._property_

expected = '.`property`'
c = str(p)
Expand All @@ -162,7 +162,7 @@ def test_can_add_two_properties(self):

def test_can_add_two_properties_underscore(self):
p = Pypher()
p.__prop1__.__prop2__
p._prop1_._prop2_

expected = '.`prop1`.`prop2`'
c = str(p)
Expand All @@ -171,7 +171,7 @@ def test_can_add_two_properties_underscore(self):

def test_can_add_two_properties_mixed(self):
p = Pypher()
p.property('prop1').__prop2__
p.property('prop1')._prop2_

expected = '.`prop1`.`prop2`'
c = str(p)
Expand Down Expand Up @@ -1332,7 +1332,7 @@ def test_can_regular_expression_pypher_object_and_string(self):
def test_can_bind_Rexp_arguments(self):
p = Pypher()
val = '".*some_val.*"'
p.n.__field__.Rexp(val)
p.n._field_.Rexp(val)
q = str(p)
params = p.bound_params
exp = 'n.`field` =~ ${val}'.format(val=get_dict_key(params, val))
Expand Down