Beispiel #1
0
 def testBuildCreatesEmptyDefault(self):
     args = argparse.Namespace(filename='foo.p8')
     self.assertEqual(0, build.do_build(args))
     self.assertTrue(os.path.exists('foo.p8'))
     with open('foo.p8', 'rb') as infh:
         txt = infh.read()
         self.assertIn(b'__gfx__\n00000000', txt)
Beispiel #2
0
 def testBuildCreatesEmptyDefault(self):
     args = argparse.Namespace(filename='foo.p8')
     self.assertEqual(0, build.do_build(args))
     self.assertTrue(os.path.exists('foo.p8'))
     with open('foo.p8') as infh:
         txt = infh.read()
         self.assertIn('__gfx__\n00000000', txt)
Beispiel #3
0
 def testErrorBothInputAndEmptyArgsSpecified(self):
     open('in.p8', 'w').close()
     self.assertTrue(os.path.exists('in.p8'))
     args = argparse.Namespace(lua='in.p8',
                               empty_lua=True,
                               filename='foo.p8')
     self.assertEqual(1, build.do_build(args))
Beispiel #4
0
    def testBuildLuaFromLuaFile(self):
        output_cart = game.Game.make_empty_game('foo.p8')
        output_cart.lua = lua.Lua.from_lines([b'print("zzz")'], version=8)
        with open('foo.p8', 'wb') as outfh:
            output_cart.to_p8_file(outfh, filename='foo.p8')
        with open('foo.p8', 'rb') as infh:
            txt = infh.read()
            self.assertIn(b'__lua__\nprint("zzz")\n', txt)

        with open('in.lua', 'wb') as outfh:
            outfh.write(b'print("hi")')
        args = argparse.Namespace(lua='in.lua', filename='foo.p8')
        self.assertEqual(0, build.do_build(args))
        with open('foo.p8', 'rb') as infh:
            txt = infh.read()
            self.assertIn(b'__lua__\nprint("hi")\n', txt)
Beispiel #5
0
    def testBuildLuaFromLuaFile(self):
        output_cart = game.Game.make_empty_game('foo.p8')
        output_cart.lua = lua.Lua.from_lines(['print("zzz")'], version=8)
        with open('foo.p8', 'w') as outfh:
            output_cart.to_p8_file(outfh, filename='foo.p8')
        with open('foo.p8') as infh:
            txt = infh.read()
            self.assertIn('__lua__\nprint("zzz")\n', txt)

        with open('in.lua', 'w') as outfh:
            outfh.write('print("hi")')
        args = argparse.Namespace(lua='in.lua', filename='foo.p8')
        self.assertEqual(0, build.do_build(args))
        with open('foo.p8') as infh:
            txt = infh.read()
            self.assertIn('__lua__\nprint("hi")\n', txt)
Beispiel #6
0
    def testBuildEmptiesSection(self):
        output_cart = game.Game.make_empty_game('foo.p8')
        output_cart.gfx.set_sprite(0, [[1, 0, 1], [0, 1, 0], [1, 0, 1]])
        output_cart.gff.set_flags(0, 7)
        with open('foo.p8', 'wb') as outfh:
            output_cart.to_p8_file(outfh, filename='foo.p8')
        with open('foo.p8', 'rb') as infh:
            txt = infh.read()
            self.assertIn(b'__gfx__\n10100000', txt)
            self.assertIn(b'__gff__\n07000000', txt)

        args = argparse.Namespace(empty_gfx=True, filename='foo.p8')
        self.assertEqual(0, build.do_build(args))
        with open('foo.p8', 'rb') as infh:
            txt = infh.read()
            self.assertIn(b'__gfx__\n00000000', txt)
            self.assertIn(b'__gff__\n07000000', txt)
Beispiel #7
0
    def testBuildEmptiesSection(self):
        output_cart = game.Game.make_empty_game('foo.p8')
        output_cart.gfx.set_sprite(0, [[1, 0, 1], [0, 1, 0], [1, 0, 1]])
        output_cart.gff.set_flags(0, 7)
        with open('foo.p8', 'w') as outfh:
            output_cart.to_p8_file(outfh, filename='foo.p8')
        with open('foo.p8') as infh:
            txt = infh.read()
            self.assertIn('__gfx__\n10100000', txt)
            self.assertIn('__gff__\n07000000', txt)

        args = argparse.Namespace(empty_gfx=True, filename='foo.p8')
        self.assertEqual(0, build.do_build(args))
        with open('foo.p8') as infh:
            txt = infh.read()
            self.assertIn('__gfx__\n00000000', txt)
            self.assertIn('__gff__\n07000000', txt)
Beispiel #8
0
    def testBuildOverwritesExisting(self):
        output_cart = game.Game.make_empty_game('foo.p8')
        output_cart.gfx.set_sprite(0, [[1, 0, 1], [0, 1, 0], [1, 0, 1]])
        output_cart.gff.set_flags(0, 7)
        with open('foo.p8', 'wb') as outfh:
            output_cart.to_p8_file(outfh, filename='foo.p8')
        with open('foo.p8', 'rb') as infh:
            txt = infh.read()
            self.assertIn(b'__gfx__\n10100000', txt)
            self.assertIn(b'__gff__\n07000000', txt)

        input_cart = game.Game.make_empty_game('in.p8')
        input_cart.gfx.set_sprite(0, [[2, 0, 2], [0, 2, 0], [2, 0, 2]])
        with open('in.p8', 'wb') as outfh:
            input_cart.to_p8_file(outfh, filename='in.p8')
        args = argparse.Namespace(gfx='in.p8', filename='foo.p8')
        self.assertEqual(0, build.do_build(args))
        with open('foo.p8', 'rb') as infh:
            txt = infh.read()
            self.assertIn(b'__gfx__\n20200000', txt)
            self.assertIn(b'__gff__\n07000000', txt)
Beispiel #9
0
    def testBuildOverwritesExisting(self):
        output_cart = game.Game.make_empty_game('foo.p8')
        output_cart.gfx.set_sprite(0, [[1, 0, 1], [0, 1, 0], [1, 0, 1]])
        output_cart.gff.set_flags(0, 7)
        with open('foo.p8', 'w') as outfh:
            output_cart.to_p8_file(outfh, filename='foo.p8')
        with open('foo.p8') as infh:
            txt = infh.read()
            self.assertIn('__gfx__\n10100000', txt)
            self.assertIn('__gff__\n07000000', txt)

        input_cart = game.Game.make_empty_game('in.p8')
        input_cart.gfx.set_sprite(0, [[2, 0, 2], [0, 2, 0], [2, 0, 2]])
        with open('in.p8', 'w') as outfh:
            input_cart.to_p8_file(outfh, filename='in.p8')
        args = argparse.Namespace(gfx='in.p8', filename='foo.p8')
        self.assertEqual(0, build.do_build(args))
        with open('foo.p8') as infh:
            txt = infh.read()
            self.assertIn('__gfx__\n20200000', txt)
            self.assertIn('__gff__\n07000000', txt)
Beispiel #10
0
 def testErrorInputFileHasWrongExtension(self):
     open('in.xxx', 'wb').close()
     self.assertTrue(os.path.exists('in.xxx'))
     args = argparse.Namespace(lua='in.xxx', filename='foo.p8')
     self.assertEqual(1, build.do_build(args))
Beispiel #11
0
 def testErrorInputFileDoesNotExist(self):
     args = argparse.Namespace(lua='doesnotexist.p8', filename='foo.p8')
     self.assertEqual(1, build.do_build(args))
Beispiel #12
0
 def testErrorOutputFilenameHasWrongExtension(self):
     args = argparse.Namespace(filename='foo.xxx')
     self.assertEqual(1, build.do_build(args))
Beispiel #13
0
 def testErrorBothInputAndEmptyArgsSpecified(self):
     open('in.p8', 'w').close()
     self.assertTrue(os.path.exists('in.p8'))
     args = argparse.Namespace(lua='in.p8', empty_lua=True,
                               filename='foo.p8')
     self.assertEqual(1, build.do_build(args))
Beispiel #14
0
 def testErrorInputFileHasWrongExtension(self):
     open('in.xxx', 'w').close()
     self.assertTrue(os.path.exists('in.xxx'))
     args = argparse.Namespace(lua='in.xxx', filename='foo.p8')
     self.assertEqual(1, build.do_build(args))
Beispiel #15
0
 def testErrorInputFileDoesNotExist(self):
     args = argparse.Namespace(lua='doesnotexist.p8', filename='foo.p8')
     self.assertEqual(1, build.do_build(args))
Beispiel #16
0
 def testErrorOutputFilenameHasWrongExtension(self):
     args = argparse.Namespace(filename='foo.xxx')
     self.assertEqual(1, build.do_build(args))