Skip to content

Commit

Permalink
refs #4 fixed bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
tell-k committed Nov 25, 2015
1 parent 3558988 commit d489530
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
language: python
python: 3.4
python: 3.5
env:
matrix:
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34
- TOXENV=py35
- TOXENV=pypy
- TOXENV=flake8
install:
- pip install tox
- if test "$TOXENV" = py34 ; then pip install coveralls ; fi
- if test "$TOXENV" = py35 ; then pip install coveralls ; fi
script: tox
after_script:
- if test "$TOXENV" = py34 ; then coveralls ; fi
- if test "$TOXENV" = py35 ; then coveralls ; fi
12 changes: 8 additions & 4 deletions csquery/structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def format_value(value):
or (value.startswith('{') and value.endswith(']'))\
or (value.startswith('[') and value.endswith('}'))\
or (value.startswith('[') and value.endswith(']')):

return six.text_type(value)
elif '=' in value:
return six.text_type(escape(value))
except AttributeError:
return six.text_type(value)

return "'{}'".format(escape(value))


Expand All @@ -59,6 +59,7 @@ def format_options(options={}):
for k, v in options.items()])


@six.python_2_unicode_compatible
class FieldValue(object):

def __init__(self, value, name=None):
Expand All @@ -79,9 +80,11 @@ def __str__(self):
return self.to_value()

def __repr__(self):
return '<{}: {}>'.format(self.__class__.__name__, self.to_value())
value = '<{}: {}>'.format(self.__class__.__name__, self.to_value())
return value.encode('utf-8') if six.PY2 else value


@six.python_2_unicode_compatible
class Expression(object):

def __init__(self, operator, options={}, *args, **kwargs):
Expand All @@ -105,7 +108,8 @@ def __str__(self):
return self.query()

def __repr__(self):
return '<{}: {}>'.format(self.__class__.__name__, self.query())
query = '<{}: {}>'.format(self.__class__.__name__, self.query())
return query.encode('utf-8') if six.PY2 else query


def _get_option(keys, options):
Expand Down
20 changes: 11 additions & 9 deletions tests/test_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def test_it(self):
assert '[1900,2000]' == self._call_fut('[1900,2000]')
assert '{,2000]' == self._call_fut('{,2000]')
assert '[1900,}' == self._call_fut('[1900,}')
assert 'field=test' == self._call_fut('field=test')
assert '1' == self._call_fut(1)
assert "actors:'Alec Guinness'" == self._call_fut(
field('Alec Guinness', 'actors')
Expand All @@ -99,26 +98,27 @@ def test_it_for_escape(self):
assert r"'te\\st'" == self._call_fut(r"te\st")
assert r"'te\'st'" == self._call_fut("te'st")

assert r"field=te\\st" == self._call_fut(r"field=te\st")
assert r"field=te\'st" == self._call_fut("field=te'st")

assert r"actors:'Alec\\Guinness'" == self._call_fut(
field(r'Alec\Guinness', 'actors')
)
assert r"actors:'Alec\'Guinness'" == self._call_fut(
field("Alec'Guinness", 'actors')
)

assert "'ジャン=ピエール・オーモン'" == self._call_fut(
'ジャン=ピエール・オーモン'
)

def test_it_for_escape__with_range_values(self):
from csquery.structured import and_

range_value = "['2000-01-01T00:00:00Z', '2010-01-01T00:00:00Z'}"
expected = "(and release_date:"
expected += "[\'2000-01-01T00:00:00Z\', \'2010-01-01T00:00:00Z\'})"
expected += "['2000-01-01T00:00:00Z', '2010-01-01T00:00:00Z'})"
assert expected == self._call_fut(and_(release_date=range_value))

expected = "(and (and release_date:"
expected += "[\'2000-01-01T00:00:00Z\', \'2010-01-01T00:00:00Z\'}))"
expected += "['2000-01-01T00:00:00Z', '2010-01-01T00:00:00Z'}))"
assert expected == self._call_fut(and_(and_(release_date=range_value)))

assert "(and _id:['tt1000000','tt1005000'])" == self._call_fut(
Expand Down Expand Up @@ -277,10 +277,12 @@ def test_it(self):
not_('テスト', field='genres'),
or_(
term('star', field='title', boost=2),
term('star', field='plot')
)
term('star', field='plot'),

),
boost='plot'
)
expected = "(and (not field=genres 'テスト') "
expected = "(and boost=plot (not field=genres 'テスト') "
expected += "(or (term field=title boost=2 'star') "
expected += "(term field=plot 'star')))"
assert expected == actual()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py27,py33,py34,pypy,flake8
envlist=py27,py33,py34,py35,pypy,flake8

[testenv]
commands=
Expand Down

0 comments on commit d489530

Please sign in to comment.