From a823aca0c89dc685d7052d972f1151239fb0f0f3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 8 May 2013 13:04:35 +0200 Subject: [PATCH] Run unit tests against hy2py Signed-off-by: Julien Danjou --- .travis.yml | 4 ++- hy/models/expression.py | 2 +- hy/models/list.py | 2 +- requirements-dev.txt | 1 - tests/test_bin.py | 65 ++++++++++++++++++++++++++++++++++++----- tox.ini | 15 ++++++++++ 6 files changed, 77 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 500d2ed..4dcaa29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,9 @@ python: # command to install dependencies install: - pip install -r requirements.txt --use-mirrors - - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2 --use-mirrors; fi + - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2 astor --use-mirrors; fi + - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install astor --use-mirrors; fi + - if [[ $TRAVIS_PYTHON_VERSION == 'pypy' ]]; then pip install astor --use-mirrors; fi - python setup.py -q install # # command to run tests script: nosetests diff --git a/hy/models/expression.py b/hy/models/expression.py index 98a35ba..4172670 100644 --- a/hy/models/expression.py +++ b/hy/models/expression.py @@ -27,4 +27,4 @@ class HyExpression(HyList): """ def __repr__(self): - return "(%s)" % (" ".join([str(x) for x in self])) + return "(%s)" % (" ".join([repr(x) for x in self])) diff --git a/hy/models/list.py b/hy/models/list.py index de2de0b..d2d4da7 100644 --- a/hy/models/list.py +++ b/hy/models/list.py @@ -37,4 +37,4 @@ class HyList(HyObject, list): return self.__class__(super(HyList, self).__add__(other)) def __repr__(self): - return "[%s]" % (" ".join([str(x) for x in self])) + return "[%s]" % (" ".join([repr(x) for x in self])) diff --git a/requirements-dev.txt b/requirements-dev.txt index 48bb15c..1e05b25 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,5 @@ tox nose -astor flake8 Sphinx coverage diff --git a/tests/test_bin.py b/tests/test_bin.py index 47f9c57..34619f1 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -1,11 +1,43 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +# Copyright (c) 2013 Julien Danjou +# Copyright (c) 2013 Will Kahn-Greene +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +import os import subprocess +import sys def run_cmd(cmd): - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + p = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True) - p.wait() - return p.returncode, p.stdout, p.stderr + stdout = "" + stderr = "" + # Read stdout and stderr otherwise if the PIPE buffer is full, we might + # wait for ever… + while p.poll() is None: + stdout += str(p.stdout.read()) + stderr += str(p.stderr.read()) + return p.returncode, stdout, stderr def test_bin_hy(): @@ -16,23 +48,23 @@ def test_bin_hy(): def test_bin_hy_stdin(): ret = run_cmd("echo \"(koan)\" | bin/hy") assert ret[0] == 0 - assert "monk" in ret[1].read().decode("utf-8") + assert "monk" in ret[1] def test_bin_hy_cmd(): ret = run_cmd("bin/hy -c \"(koan)\"") assert ret[0] == 0 - assert "monk" in ret[1].read().decode("utf-8") + assert "monk" in ret[1] ret = run_cmd("bin/hy -c \"(koan\"") assert ret[0] == 1 - assert "LexException" in ret[1].read().decode("utf-8") + assert "LexException" in ret[1] def test_bin_hy_icmd(): ret = run_cmd("echo \"(ideas)\" | bin/hy -i \"(koan)\"") assert ret[0] == 0 - output = ret[1].read().decode("utf-8") + output = ret[1] assert "monk" in output assert "figlet" in output @@ -41,4 +73,21 @@ def test_bin_hy_icmd(): def test_bin_hy_file(): ret = run_cmd("bin/hy eg/nonfree/halting-problem/halting.hy") assert ret[0] == 0 - assert "27" in ret[1].read().decode("utf-8") + assert "27" in ret[1] + + +def test_hy2py(): + # XXX Astor doesn't seem to support astor :( + if sys.version_info[0] == 3: + return + + i = 0 + for dirpath, dirnames, filenames in os.walk("tests/native_tests"): + for f in filenames: + if f.endswith(".hy"): + i += 1 + ret = run_cmd("bin/hy2py " + os.path.join(dirpath, f)) + assert ret[0] == 0, f + assert len(ret[1]) > 1, f + assert len(ret[2]) == 0, f + assert i diff --git a/tox.ini b/tox.ini index 8e4f011..1fb410a 100644 --- a/tox.ini +++ b/tox.ini @@ -6,8 +6,23 @@ deps = nose setuptools +[testenv:pypy] +commands = nosetests +deps = + astor + nose + setuptools + +[testenv:py27] +commands = nosetests +deps = + astor + nose + setuptools + [testenv:py26] deps = + astor nose setuptools unittest2