From fac002fc27cf645293a7e0c5d257603e50c736b3 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Tue, 24 Nov 2020 20:57:07 -0500 Subject: [PATCH 01/15] Maybe this is a good test for the thing --- src/imaginary/test/test_actions.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/imaginary/test/test_actions.py b/src/imaginary/test/test_actions.py index a866349..d89eb3b 100644 --- a/src/imaginary/test/test_actions.py +++ b/src/imaginary/test/test_actions.py @@ -327,6 +327,24 @@ def testTakeImmoveable(self): ["Test Player regards an immoveable thoughtfully."], ) + def testTakeImmoveableByLink(self): + """ + A L{Thing} with C{portable} set to C{False} cannot be taken via a link to + 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 north", + ["You cannot take an immoveable."], + [], + ) def testDrop(self): self._test( From 2d5e4699472354c94441a83dacfcc0c61aaf1c5d Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 26 Nov 2020 12:01:05 -0500 Subject: [PATCH 02/15] Match the text actually generated by CannotMove would be nice to have an abstraction for this I guess --- src/imaginary/test/test_actions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/imaginary/test/test_actions.py b/src/imaginary/test/test_actions.py index d89eb3b..c7f2799 100644 --- a/src/imaginary/test/test_actions.py +++ b/src/imaginary/test/test_actions.py @@ -342,8 +342,8 @@ def testTakeImmoveableByLink(self): self._test( "take north", - ["You cannot take an immoveable."], - [], + ["An immoveable cannot be taken."], + ["Test Player regards an immoveable thoughtfully."], ) def testDrop(self): From f07cb1967acecd57f292ff698bf84cb2b683aa12 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 26 Nov 2020 12:01:55 -0500 Subject: [PATCH 03/15] Change another test to avoid trying to move a non-portable It worked before because it moved from nowhere, which is now disallowed --- src/imaginary/test/test_objects.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/imaginary/test/test_objects.py b/src/imaginary/test/test_objects.py index 7628dad..9d412b0 100644 --- a/src/imaginary/test/test_objects.py +++ b/src/imaginary/test/test_objects.py @@ -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) From 39cd7f582b1376c3dff4271b1ceea14d2f8fba62 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 26 Nov 2020 12:02:15 -0500 Subject: [PATCH 04/15] Disallow all non-portable movement Previously something non-portable could move as long as it had no location. Now non-portable things cannot move. --- src/imaginary/objects.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/imaginary/objects.py b/src/imaginary/objects.py index 3c76f60..aeb73f7 100644 --- a/src/imaginary/objects.py +++ b/src/imaginary/objects.py @@ -293,6 +293,9 @@ 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) @@ -300,8 +303,6 @@ def moveTo(self, where, arrivalEventFactory=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() From 6d15d6ffb9d67cc03e80661eacade14ba3c84188 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 26 Nov 2020 17:34:29 -0500 Subject: [PATCH 05/15] The link stuff was an early hypothesis that didn't pan out The real reason the behavior differs is that the take action has special logic to exclude taking your location. --- src/imaginary/test/test_actions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/imaginary/test/test_actions.py b/src/imaginary/test/test_actions.py index c7f2799..ffd2006 100644 --- a/src/imaginary/test/test_actions.py +++ b/src/imaginary/test/test_actions.py @@ -327,10 +327,10 @@ def testTakeImmoveable(self): ["Test Player regards an immoveable thoughtfully."], ) - def testTakeImmoveableByLink(self): + def testTakeNonContainingImmoveable(self): """ - A L{Thing} with C{portable} set to C{False} cannot be taken via a link to - it. + 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, @@ -341,7 +341,7 @@ def testTakeImmoveableByLink(self): objects.Exit.link(self.location, immoveable, u'north') self._test( - "take north", + "take immoveable", ["An immoveable cannot be taken."], ["Test Player regards an immoveable thoughtfully."], ) From 5ddc57d29c3b095fc03ebc36562309fc4a123df8 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Thu, 26 Nov 2020 22:01:57 -0500 Subject: [PATCH 06/15] Make the protagonist in example_game a manipulator --- doc/examples/example_world.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/examples/example_world.py b/doc/examples/example_world.py index 3f7ca58..4ffc83a 100644 --- a/doc/examples/example_world.py +++ b/doc/examples/example_world.py @@ -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 @@ -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( From ca574c0940febc70e6a239e460482393482b4ff7 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 28 Nov 2020 11:33:00 -0500 Subject: [PATCH 07/15] Don't install ExampleGame just to run the Imaginary tests --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 262e76b..09d5af8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,13 +61,13 @@ 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 . + pip freeze - - name: "Run Tests" + - name: "Run Imaginary Tests" run: | python -m coverage run -m twisted.trial imaginary coverage combine From d2e3f725d81b0a4662172a373c12414c91a5b819 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 28 Nov 2020 11:33:22 -0500 Subject: [PATCH 08/15] Install ExampleGame and run its tests separately, then upload all coverage --- .github/workflows/ci.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09d5af8..14c9c53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,14 +70,31 @@ jobs: - name: "Run Imaginary Tests" run: | python -m coverage run -m twisted.trial imaginary + + - name: "Install ExampleGame and dependencies" + run: | + pip install ./ExampleGame + pip freeze + + - name: "Run ExampleGame Tests" + run: | + python -m coverage run -m twisted.trial examplegame + + - name: "Upload Coverage Results" + run: | + # Combine coverage from all of the test runs. coverage combine + + # 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 - - name: "Upload Coverage Results" - run: | + # Okay actually upload it. pip install coveralls COVERALLS_REPO_TOKEN=1oyBvUgwFpx0lZfqAXiqM8LPmgKk2Y7OL coveralls From 737ba78f74fa0bc9ac052847b55f5d526d497c45 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 28 Nov 2020 11:39:31 -0500 Subject: [PATCH 09/15] An effort at coverage configuration supporting two projects --- .coveragerc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 998ef4d..deffaf4 100644 --- a/.coveragerc +++ b/.coveragerc @@ -4,12 +4,17 @@ parallel = True source_pkgs = imaginary + examplegame omit = # Vendored source file, don't worry about its coverage. */imaginary/pyparsing.py [paths] -source = +imaginary = src/ */site-packages/ + +examplegame = + ExampleGame/ + */site-packages/ From 3b434a66fe3e3d2a071c08214336c2043da92571 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sun, 29 Nov 2020 09:11:00 -0500 Subject: [PATCH 10/15] Split the ExampleGame coverage config into a separate file --- .coveragerc | 7 +------ .coveragerc-examplegame | 11 +++++++++++ .github/workflows/ci.yml | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .coveragerc-examplegame diff --git a/.coveragerc b/.coveragerc index deffaf4..30eceb4 100644 --- a/.coveragerc +++ b/.coveragerc @@ -4,17 +4,12 @@ parallel = True source_pkgs = imaginary - examplegame omit = # Vendored source file, don't worry about its coverage. */imaginary/pyparsing.py [paths] -imaginary = +source_paths = src/ */site-packages/ - -examplegame = - ExampleGame/ - */site-packages/ diff --git a/.coveragerc-examplegame b/.coveragerc-examplegame new file mode 100644 index 0000000..59d3d5e --- /dev/null +++ b/.coveragerc-examplegame @@ -0,0 +1,11 @@ +[run] +branch = True +parallel = True + +source_pkgs = + examplegame + +[paths] +source_paths = + ExampleGame/ + */site-packages/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14c9c53..e43a3c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: - name: "Run ExampleGame Tests" run: | - python -m coverage run -m twisted.trial examplegame + python -m coverage run --rcfile .coveragerc-examplegame -m twisted.trial examplegame - name: "Upload Coverage Results" run: | From d5b1744eadeecfb17fe1fae3e670827be960e60b Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sun, 29 Nov 2020 09:21:36 -0500 Subject: [PATCH 11/15] Try doing everything separately --- .github/workflows/ci.yml | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e43a3c9..7e8ece9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,12 +64,15 @@ jobs: - name: "Install Imaginary and dependencies" run: | pip install --upgrade pip setuptools coverage - pip install . + pip install coveralls . pip freeze - name: "Run Imaginary Tests" run: | python -m coverage run -m twisted.trial imaginary + coverage combine + COVERALLS_REPO_TOKEN=1oyBvUgwFpx0lZfqAXiqM8LPmgKk2Y7OL coveralls + coverage erase - name: "Install ExampleGame and dependencies" run: | @@ -79,22 +82,6 @@ jobs: - name: "Run ExampleGame Tests" run: | python -m coverage run --rcfile .coveragerc-examplegame -m twisted.trial examplegame - - - name: "Upload Coverage Results" - run: | - # Combine coverage from all of the test runs. - coverage combine - - # 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 + coverage combine --rcfile .coveragerc-examplegame + COVERALLS_REPO_TOKEN=1oyBvUgwFpx0lZfqAXiqM8LPmgKk2Y7OL coveralls --rcfile .coveragerc-examplegame + coverage erase From a3d81ea2c34f95786c4eee1179c21fff9a5d2050 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sun, 29 Nov 2020 09:28:07 -0500 Subject: [PATCH 12/15] Try this slightly more DRY approach? It's not very much more DRY but it feels nicer. --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e8ece9..57d19ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,15 +64,15 @@ jobs: - name: "Install Imaginary and dependencies" run: | pip install --upgrade pip setuptools coverage - pip install coveralls . + pip install . pip freeze - 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 - COVERALLS_REPO_TOKEN=1oyBvUgwFpx0lZfqAXiqM8LPmgKk2Y7OL coveralls - coverage erase - name: "Install ExampleGame and dependencies" run: | @@ -82,6 +82,23 @@ jobs: - name: "Run ExampleGame Tests" run: | python -m coverage run --rcfile .coveragerc-examplegame -m twisted.trial examplegame - coverage combine --rcfile .coveragerc-examplegame - COVERALLS_REPO_TOKEN=1oyBvUgwFpx0lZfqAXiqM8LPmgKk2Y7OL coveralls --rcfile .coveragerc-examplegame - coverage erase + # 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 From e093d6d0f4e8b70fde4e326347fd9310aa91416d Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 5 Dec 2020 19:59:45 -0500 Subject: [PATCH 13/15] Correct rogue wordwrap --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57d19ed..b890e89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,9 +94,9 @@ jobs: # 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. + # 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. From 71eda3c9b98ad725d836d37f36c9bdd7e5b32567 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 5 Dec 2020 20:01:11 -0500 Subject: [PATCH 14/15] Use python-info-action instead of `pip freeze` --- .github/workflows/ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b890e89..632c12c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,9 @@ jobs: run: | pip install --upgrade pip setuptools coverage pip install . - pip freeze + + - name: "Dump Environment Info" + uses: "twisted/python-info-action@v1.0.1" - name: "Run Imaginary Tests" run: | @@ -77,7 +79,9 @@ jobs: - name: "Install ExampleGame and dependencies" run: | pip install ./ExampleGame - pip freeze + + - name: "Dump Environment Info" + uses: "twisted/python-info-action@v1.0.1" - name: "Run ExampleGame Tests" run: | From 692fe5144c11514864c995f7101a27b4b927a984 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 5 Dec 2020 20:02:36 -0500 Subject: [PATCH 15/15] This renaming was inconsequential --- .coveragerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index 30eceb4..b49c15d 100644 --- a/.coveragerc +++ b/.coveragerc @@ -10,6 +10,6 @@ omit = */imaginary/pyparsing.py [paths] -source_paths = +paths = src/ */site-packages/