Skip to content

Commit

Permalink
Merge branch 'master' into 98.vending-machine-description
Browse files Browse the repository at this point in the history
  • Loading branch information
glyph committed Jul 6, 2021
2 parents f5d89b4 + ff081a0 commit 3874530
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Expand Up @@ -10,6 +10,6 @@ omit =
*/imaginary/pyparsing.py

[paths]
source =
paths =
src/
*/site-packages/
11 changes: 11 additions & 0 deletions .coveragerc-examplegame
@@ -0,0 +1,11 @@
[run]
branch = True
parallel = True

source_pkgs =
examplegame

[paths]
source_paths =
ExampleGame/
*/site-packages/
43 changes: 34 additions & 9 deletions .github/workflows/ci.yml
Expand Up @@ -61,23 +61,48 @@ jobs:
with:
python-version: "${{ matrix.python-version }}"

- name: "Install Python packages"
- name: "Install Imaginary and dependencies"
run: |
pip install --upgrade pip setuptools coverage
pip install . ./ExampleGame
pip list
pip install .
- name: "Run Tests"
- name: "Dump Environment Info"
uses: "twisted/python-info-action@v1.0.1"

- name: "Run Imaginary Tests"
run: |
python -m coverage run -m twisted.trial imaginary
# Combine the Imaginary coverage results in a .coverage data file.
# Like the `coverage run` above, use the default .coveragerc.
coverage combine
# --ignore-errors is required here because the path resolution can't
# --figure out the right place to find Twisted dropin source files.
# --Without --ignore-errors the report fails when it fails to read
# --these sources.
coverage report --show-missing --ignore-errors
- name: "Install ExampleGame and dependencies"
run: |
pip install ./ExampleGame
- name: "Dump Environment Info"
uses: "twisted/python-info-action@v1.0.1"

- name: "Run ExampleGame Tests"
run: |
python -m coverage run --rcfile .coveragerc-examplegame -m twisted.trial examplegame
# Combine the ExampleGame coverage results into the existing
# .coverage data file. Make sure to use the ExampleGame .coveragerc
# so paths are resolved correctly.
coverage combine --rcfile .coveragerc-examplegame --append
- name: "Upload Coverage Results"
run: |
# For fun, I guess, dump a text report to CI output. These aren't
# too much fun to read but perhaps it's useful sometimes if the CI
# reporting service is misbehaving.
#
# --ignore-errors is required here because the path resolution can't
# figure out the right place to find Twisted dropin source files.
# Without --ignore-errors the report fails when it fails to read
# these sources.
coverage report --show-missing --ignore-errors
# Okay actually upload it.
pip install coveralls
COVERALLS_REPO_TOKEN=1oyBvUgwFpx0lZfqAXiqM8LPmgKk2Y7OL coveralls
7 changes: 7 additions & 0 deletions doc/examples/example_world.py
Expand Up @@ -5,6 +5,9 @@
from imaginary.objects import Thing, Container, Exit
from imaginary.garments import createShirt, createPants
from imaginary.iimaginary import IClothing, IClothingWearer
from imaginary.manipulation import (
Manipulator,
)

from examplegame.squeaky import Squeaker

Expand All @@ -23,6 +26,10 @@ def room(name, description):
origin = room("The Beginning", "Everything here looks fresh and new.")
world = ImaginaryWorld(store=store, origin=origin)
protagonist = world.create("An Example Player")
# Allow the protagonist to use the mildly privileged "manipulator"
# actions.
Manipulator.createFor(protagonist)

shirt = createShirt(store=store, name="shirt", location=world.origin)
pants = createPants(store=store, name="pants", location=world.origin)
middle = room(
Expand Down
5 changes: 3 additions & 2 deletions src/imaginary/objects.py
Expand Up @@ -293,15 +293,16 @@ def moveTo(self, where, arrivalEventFactory=None):
.capitalizeConcept(),
" won't fit inside itself."]))

if not self.portable:
raise eimaginary.CannotMove(self, where)

oldLocation = self.location
for restriction in self.powerupsFor(iimaginary.IMovementRestriction):
restriction.movementImminent(self, where)
if oldLocation is not None:
events.DepartureEvent(oldLocation, self).broadcast()
if where is not None:
where = iimaginary.IContainer(where)
if oldLocation is not None and not self.portable:
raise eimaginary.CannotMove(self, where)
where.add(self)
if arrivalEventFactory is not None:
arrivalEventFactory(self).broadcast()
Expand Down
18 changes: 18 additions & 0 deletions src/imaginary/test/test_actions.py
Expand Up @@ -327,6 +327,24 @@ def testTakeImmoveable(self):
["Test Player regards an immoveable thoughtfully."],
)

def testTakeNonContainingImmoveable(self):
"""
A L{Thing} with C{portable} set to C{False} cannot be taken even if the
taker is not contained by it. it.
"""
immoveable = objects.Thing(
store=self.store,
name=u"immoveable",
portable=False,
)
objects.Container.createFor(immoveable)
objects.Exit.link(self.location, immoveable, u'north')

self._test(
"take immoveable",
["An immoveable cannot be taken."],
["Test Player regards an immoveable thoughtfully."],
)

def testDrop(self):
self._test(
Expand Down
9 changes: 6 additions & 3 deletions src/imaginary/test/test_objects.py
Expand Up @@ -101,11 +101,14 @@ def testNonPortable(self):
Test that the C{portable} flag is respected and prevents movement
between locations.
"""
obj = objects.Thing(store=self.store, name=u"mountain")
obj.portable = False
room = objects.Thing(store=self.store, name=u"place")
objects.Container.createFor(room, capacity=1000)
obj.moveTo(room)
obj = objects.Thing(
store=self.store,
name=u"mountain",
portable=False,
location=room,
)
elsewhere = objects.Thing(store=self.store, name=u"different place")
container = objects.Container.createFor(elsewhere, capacity=1000)
self.assertRaises(eimaginary.CannotMove, obj.moveTo, elsewhere)
Expand Down

0 comments on commit 3874530

Please sign in to comment.