Skip to content

Commit

Permalink
Merge pull request ethereum#102 from pipermerriam/piper/add-travis-ci…
Browse files Browse the repository at this point in the history
…-testing

Python 3 Support
  • Loading branch information
vbuterin authored Jun 22, 2016
2 parents a33ef61 + 4501e9a commit 9dc8c1c
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: python
python:
- "3.5"
env:
matrix:
- TOX_ENV=py27
- TOX_ENV=py34
- TOX_ENV=py35
cache: pip
install:
- "travis_retry pip install setuptools --upgrade"
- "travis_retry pip install tox"
script:
- tox -e $TOX_ENV
after_script:
- cat .tox/$TOX_ENV/log/*.log
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
Installation:
# Installation:

```make && sudo make install```
`make && sudo make install`


# Testing

Testing is done using `pytest` and `tox`.

```bash
$ pip install tox -r requirements-dev.txt
```


To run the test suite in your current python version:

```bash
$ py.test
```


To run the full test suite across all supported python versions:

```bash
$ tox
```
4 changes: 2 additions & 2 deletions examples/cyberdyne/market.se
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ data current_epoch
data price
data volume

extern heap: [pop:_:i, push:i:_, size:_:i, top:_:i]
extern subcurrency: [balance:i:i, change_ownership:i:_, issue:ii:_, last_tx:_:a, send:ii:i]
extern heap: [pop:[]:int256, push:[int256]:_, set_owner:[int256]:_, size:[]:int256, top:[]:int256]
extern subcurrency: [balance:[int256]:int256, change_ownership:[int256]:_, issue:[int256,int256]:_, last_tx:[]:int256[], send:[int256,int256]:int256]

# Initialize with [ buy_heap, sell_heap, first_subcurrency, second_subcurrency ]
def init_market(buy_heap, sell_heap, first_subcurrency, second_subcurrency):
Expand Down
8 changes: 4 additions & 4 deletions examples/cyberdyne/test/test_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from serpent import mk_full_signature

def decode_buy_order(order):
buyprice = -(order / 2**208)
buyfcvalue = (order / 2**160) % 2**48
buyprice = -(order // 2**208)
buyfcvalue = (order // 2**160) % 2**48
buyer = order % 2**160
return (buyprice, buyfcvalue, buyer)

def decode_sell_order(order):
sellprice = order / 2**208
sellscvalue = (order / 2**160) % 2**48
sellprice = order // 2**208
sellscvalue = (order // 2**160) % 2**48
seller = order % 2**160
return (sellprice, sellscvalue, seller)

Expand Down
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest==2.9.2
#ethereum==1.3.6
https://github.com/ethereum/pyethereum/tarball/develop
14 changes: 10 additions & 4 deletions serpent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

VERSION = '2.0.2'

if sys.version_info.major == 2:
str_types = (bytes, str, unicode)
else:
str_types = (bytes, str)


def strtobytes(x):
return x.encode('ascii') if isinstance(x, str) else x

Expand Down Expand Up @@ -81,7 +87,7 @@ def takelist(x):
def pre_transform(code, params):
code2 = ''
for k, v in params.items():
if isinstance(v, (str, bytes, unicode)):
if isinstance(v, str_types):
v = '"' + str(v) + '"'
code2 += 'macro $%s:\n %s\n' % (k, v)
if os.path.exists(code):
Expand All @@ -102,8 +108,8 @@ def pre_transform(code, params):
serialize = lambda x: pyext.serialize(takelist(strtobytes(x)))
deserialize = lambda x: map(node, pyext.deserialize(x))
mk_signature = lambda code, **kwargs: pyext.mk_signature(strtobytes(pre_transform(code, kwargs)))
mk_full_signature = lambda code, **kwargs: json.loads(pyext.mk_full_signature(strtobytes(pre_transform(code, kwargs))))
mk_contract_info_decl = lambda code, **kwargs: json.loads(pyext.mk_contract_info_decl(strtobytes(pre_transform(code, kwargs))))
mk_full_signature = lambda code, **kwargs: json.loads(bytestostr(pyext.mk_full_signature(strtobytes(pre_transform(code, kwargs)))))
mk_contract_info_decl = lambda code, **kwargs: json.loads(bytestostr(pyext.mk_contract_info_decl(strtobytes(pre_transform(code, kwargs)))))
get_prefix = lambda x: pyext.get_prefix(strtobytes(x)) % 2**32

if sys.version_info.major == 2:
Expand Down Expand Up @@ -222,7 +228,7 @@ def main():
kwargs['source'] = 'cmdline'
o = globals()[cmd](*args, **kwargs)
if cmd in ['mk_full_signature', 'mk_contract_info_decl']:
print json.dumps(o)
print(json.dumps(o))
elif isinstance(o, (Token, Astnode, dict, list)):
print(repr(o))
elif cmd in ['mk_full_signature', 'get_prefix']:
Expand Down
12 changes: 10 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,13 @@
'console_scripts': [
'serpent = serpent:main',
],
}
),
},
classifiers=[
'Intended Audience :: Developers',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
)
10 changes: 10 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tox]
envlist=
py27,
py34,
py35

[testenv]
commands=py.test --tb native {posargs:.}
deps =
-r{toxinidir}/requirements-dev.txt

0 comments on commit 9dc8c1c

Please sign in to comment.