Sunday, 12 December 2010

Saving Narratives, Loading Scenes

Still banging away at a Scene editor for clonemaster, in case anyone's losing the plot. It happens to me fairly regularly...

Saving with a narrative list

        [Test]
        def save_with_narrs():
                sc = Scene()
                sc.name         = "has_narratives"
                sc.default      = "narrative_1"
                sc.desc         = "see if narratives export correctly"
                sc.Add_narrative("narrative_1", "first narrative")
                sc.Add_narrative("narrative_2", "second narrative")
#
#               this is what we expect the output to look like
#
                target = detab("""
                        <scene name="has_narratives" default="narrative_1" desc="see if narratives export correctly">
                         <narrative name="narrative_1" desc="first narrative" />
                         <narrative name="narrative_2" desc="second narrative" />
                        </scene>
                """)
#
#               I'll over load the load and save funcs to take a stream
#               It's easier to test using stringwriters and readers.
#               I can overload the filename version to create a reader and
#               call this version, so the tests will largely still apply
#
                using sw = StringWriter():
                        sc.save(sw)
#
#                       stringifying the writer gets the underlying string
#
                        result = "${sw}"
                        Assert.AreEqual(target, result)


That passes. This is the next test:

        [Test]
        def simple_load():
                sc = Scene()
#
#               load from this string
#
                xml_text = detab("""
                        <scene name="intro" default="waking_up" desc="here we go" />
                """)
#
#               I'll over load the load and save funcs to take a stream
#               It's easier to test using stringwriters and readers.
#               I can overload the filename version to create a reader and
#               call this version, so the tests will largely still apply
#
                using sw = StringReader(xml_text):
                        sc.load(sw)

                Assert.AreEqual("intro", sc.name)
                Assert.AreEqual("waking_up", sc.default)
                Assert.AreEqual("here we go", sc.desc)


I want to try and do these in parallel. No point in getting all the saves working perfectly, only to realise there's a fundamental problem loading it back in again.

No comments: