Skip to content

Commit

Permalink
Merge pull request #19 from py3minepi/pytest
Browse files Browse the repository at this point in the history
Introduce Pytest, Tox, Coverage
  • Loading branch information
dbrgn committed Sep 30, 2014
2 parents 1f8a769 + 4491667 commit 456702b
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 54 deletions.
17 changes: 17 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[run]
source =
minecraft

[report]
exclude_lines =
# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
*.pyc
*.swp
.idea/
.cache/
.tox/
*.egg-info/
.coverage
17 changes: 10 additions & 7 deletions .travis-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CHROOT_ARCH=armhf
HOST_DEPENDENCIES="debootstrap qemu-user-static binfmt-support sbuild"

# Debian package dependencies for the chrooted environment
GUEST_DEPENDENCIES="sudo python3 python3-pip"
GUEST_DEPENDENCIES="sudo python2.7 python3 python-pip python3-pip"

# Command used to run the tests

Expand All @@ -30,6 +30,7 @@ function setup_arm_chroot {
# Create file with environment variables which will be used inside chrooted
# environment
echo "export ARCH=${ARCH}" > envvars.sh
echo "export TOXENV=${TOXENV}" > envvars.sh
echo "export TRAVIS_BUILD_DIR=${TRAVIS_BUILD_DIR}" >> envvars.sh
chmod a+x envvars.sh

Expand All @@ -51,19 +52,21 @@ function setup_arm_chroot {

if [ -e "/.chroot_is_done" ]; then
# We are inside ARM chroot
echo "Running inside chrooted environment"
echo "--- Running inside chrooted environment"

. ./envvars.sh

echo "Running tests"
echo "Environment: $(uname -a)"
echo "--- Running tests"
echo "--- Environment: $(uname -a)"
echo "--- Working directory: $(pwd)"
ls -la

sudo pip-3.2 install pytest
py.test
sudo pip install tox
tox
else
if [ "${ARCH}" = "arm" ]; then
# ARM test run, need to set up chrooted environment first
echo "Setting up chrooted ARM environment"
echo "--- Setting up chrooted ARM environment"
setup_arm_chroot
fi
fi
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: erlang

env:
- ARCH=arm

- ARCH=arm TOXENV=py27
- ARCH=arm TOXENV=py32
- ARCH=arm TOXENV=cov
matrix:
allow_failures:
- env: ARCH=arm TOXENV=cov
script:
- "bash -ex .travis-ci.sh"

- bash -ex .travis-ci.sh
File renamed without changes.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include README.rst AUTHORS.txt LICENSE.txt
recursive-exclude * *.pyc
30 changes: 0 additions & 30 deletions README.md

This file was deleted.

41 changes: 41 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
README
======

.. image:: https://secure.travis-ci.org/py3minepi/py3minepi.png?branch=master
:alt: Build status
:target: https://travis-ci.org/py3minepi/py3minepi

.. image:: https://coveralls.io/repos/py3minepi/py3minepi/badge.png?branch=master
:alt: Coverage
:target: https://coveralls.io/r/py3minepi/py3minepi


`Minecraft: Pi Edition <http://pi.minecraft.net/>`__ is awesome.

However it uses Python 2. We're moving it to Python 3 (without any official
approval) and offering it for download here.

We hope this makes people's lives easier.

Goals
-----

- [x] Python 3
- [ ] TESTS (pytest, tox, flake8, coverage)
- [ ] More intuitive API focusing on getting some mining done and hiding implementation details
- [ ] Backwards compatibility with the existing codebase (with `__init__` foo) so existing scripts will continue to work
- [ ] Connection backends (socket, in memory for testing)
- [ ] Clever socket usage so disconnects can be dealt with
- [ ] Make the code base more readable and thus maintainable
- [ ] A CI test suite running an rPi emulator (with Travis)
- [ ] Improve code documentation both in the code base and with a RTD page
- [ ] Find missing functions that are in the java API but not described in the python API

Links
-----

- `Raspberry Pi <http://www.raspberrypi.org/>`_
- `Minecraft Pi <http://pi.minecraft.net/>`_
- `Minecraft Pi Usage page <http://www.raspberrypi.org/documentation/usage/minecraft/>`_
- `Original API reference <http://www.stuffaboutcode.com/p/minecraft-api-reference.html>`_
- `Martin O'Hanlon GitHub <https://github.com/martinohanlon>`_ (useful test projects)
2 changes: 0 additions & 2 deletions VERSION.txt

This file was deleted.

2 changes: 0 additions & 2 deletions minecraft/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,3 @@ class blockType(Enum):
FENCE_GATE = 107
GLOWING_OBSIDIAN = 246
NETHER_REACTOR_CORE = 247


10 changes: 3 additions & 7 deletions minecraft/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ def __init__(self, address="localhost", port=4711):

def getBlock(self, *args):
"""Get block (x,y,z) => id:int"""

return int(self._conn.sendReceive("world.getBlock", intFloor(args)))

def getBlockWithData(self, *args):
"""Get block with data (x,y,z) => Block"""

ans = self._conn.sendReceive("world.getBlockWithData", intFloor(args))
return Block(*map(int, ans.split(",")))

Expand All @@ -149,19 +148,17 @@ def getBlockWithData(self, *args):
"""
def getBlocks(self, *args):
"""Get a cuboid of blocks (x0,y0,z0,x1,y1,z1) => [id:int]"""

return int(self._conn.sendReceive("world.getBlocks", intFloor(args)))

def setBlock(self, *args):
"""Set block (x,y,z,id,[data])"""
self._conn.send("world.setBlock", intFloor(args))


def setBlocks(self, *args): #leaving thisone alone for now
def setBlocks(self, *args): # leaving thisone alone for now
"""Set a cuboid of blocks (x0,y0,z0,x1,y1,z1,id,[data])"""
self._conn.send("world.setBlocks", intFloor(args))


def getGroundHeight(self, *args):
"""Get the height of the world (x,z) => int"""

Expand All @@ -184,7 +181,6 @@ def postToChat(self, msg):
"""Post a message to the game chat"""
self._conn.send("chat.post", msg)


def setting(self, setting, status):
"""Set a world setting (setting, status). keys: world_immutable, nametags_visible"""
self._conn.send("world.setting", setting, 1 if bool(status) else 0)
Expand Down
1 change: 0 additions & 1 deletion minecraft/mock_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ class ThreadedServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
server_thread.daemon = False
server_thread.start()
print("server is now running on port {}".format(PORT))

10 changes: 10 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[pytest]
addopts = --tb=short --doctest-glob='*.rst' --pep8
python_files = test_*.py
norecursedirs = .* VIRTUAL build docs
pep8ignore =
*.py E126 E127 E128
setup.py ALL
*/tests/* ALL
*/docs/* ALL
pep8maxlinelength = 99
30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
import io
from setuptools import setup, find_packages

with io.open('README.rst', mode='r', encoding='utf8') as f:
readme = f.read()

setup(name='py3minepi',
version='0.0.1',
description='A better minecraft pi library.',
url='https://github.com/py3minepi/py3minepi',
packages=find_packages(exclude=['*.tests', '*.tests.*', 'tests.*', 'tests']),
zip_safe=True,
include_package_data=True,
keywords='minecraft raspberry pi mcpi py3minepi',
long_description=readme,
classifiers=[
'Development Status :: Development Status :: 3 - Alpha',
'Environment :: X11 Applications',
'Intended Audience :: Education',
'Intended Audience :: Developers',
'License :: OSI Approved :: Other/Proprietary License', # TODO fix
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
)
26 changes: 26 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
############ Base configuration ############
[tox]
envlist =
py27,py32,py33,py34,cov

[testenv]
deps =
pytest
pytest-pep8
commands =
pip install -e .
py.test

############ Special Cases ############

[testenv:cov]
basepython=python3.2
deps =
{[testenv]deps}
coverage
coveralls
commands =
pip install -e .
coverage run --source minecraft -m py.test
coverage report
coveralls

0 comments on commit 456702b

Please sign in to comment.