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"])