diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6b30cb1 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/README.md b/README.md index 03dfcc1..d0a26b8 100644 --- a/README.md +++ b/README.md @@ -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 +``` diff --git a/examples/cyberdyne/market.se b/examples/cyberdyne/market.se index ec11925..f29763e 100644 --- a/examples/cyberdyne/market.se +++ b/examples/cyberdyne/market.se @@ -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): diff --git a/examples/cyberdyne/test/test_market.py b/examples/cyberdyne/test/test_market.py index 0abbc91..d237283 100644 --- a/examples/cyberdyne/test/test_market.py +++ b/examples/cyberdyne/test/test_market.py @@ -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) diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..f161ac1 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +pytest==2.9.2 +#ethereum==1.3.6 +https://github.com/ethereum/pyethereum/tarball/develop diff --git a/serpent.py b/serpent.py index a05d35a..3b6d7ff 100644 --- a/serpent.py +++ b/serpent.py @@ -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 @@ -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): @@ -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: @@ -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']: diff --git a/setup.py b/setup.py index 24ce343..ad08aca 100644 --- a/setup.py +++ b/setup.py @@ -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', + ], +) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..5701ef7 --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +envlist= + py27, + py34, + py35 + +[testenv] +commands=py.test --tb native {posargs:.} +deps = + -r{toxinidir}/requirements-dev.txt