From c71c2fa07a2ac67ce2673701e07090f0fd8a4b81 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 7 Aug 2019 12:28:29 +0300 Subject: [PATCH] Fix the 'picturegallery' game. See https://github.com/shlomif/PySolFC/issues/140 . Thanks to @scottfurry for testing. --- pysollib/struct_new.py | 6 ++++++ tests/lib/pysol_tests/game_drag.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pysollib/struct_new.py b/pysollib/struct_new.py index b345f003..292be32b 100644 --- a/pysollib/struct_new.py +++ b/pysollib/struct_new.py @@ -17,3 +17,9 @@ class NewStruct(object): ret = self.__class__() ret.__dict__.update(self.__dict__) return ret + + def addattr(self, **kw): + for k in kw.keys(): + if k in self.__dict__: + raise AttributeError(k) + self.__dict__.update(kw) diff --git a/tests/lib/pysol_tests/game_drag.py b/tests/lib/pysol_tests/game_drag.py index ec976232..a5a833b9 100644 --- a/tests/lib/pysol_tests/game_drag.py +++ b/tests/lib/pysol_tests/game_drag.py @@ -2,7 +2,7 @@ import unittest -from pysollib.game import GameDrag +from pysollib.game import GameDrag, GameStacks class MyTests(unittest.TestCase): @@ -10,3 +10,9 @@ class MyTests(unittest.TestCase): d = GameDrag() d.shadows.append("test") self.assertTrue(len(d.shadows)) + + def test_addattr(self): + s = GameStacks() + s.addattr(tableaux=[]) + s.tableaux.append("myval") + self.assertEqual(s.tableaux, ["myval"])