예제 #1
0
class TestPresentationParser(CheeseBoysTestCase):
    """Test the use of a PresentationParser"""

    def setUp(self):
        CheeseBoysTestCase.setUp(self)
        self.pparser = PresentationParser("dummy")
        # init parameter, as I will never call .open()
        self.pparser._text = FAKE_CBP_FILE
        self.pparser._lines = self.pparser._text.split("\n")

    def testVersionLine(self):
        """Test if version line is found and parsed right"""
        line = self.pparser._lines[5]
        self.assertRaises(CBPParsingException, self.pparser._checkVersionLineSyntax, line, 6)
        line = self.pparser._lines[3]
        self.assertRaises(CBPParsingException, self.pparser._checkVersionLineSyntax, line, 4)
        self.assertRaises(
            CBPParsingException,
            self.pparser._checkVersionLineSyntax,
            line.strip() + "   # no comment on version line",
            4,
        )
        self.assertEquals(self.pparser._checkVersionLineSyntax(line.strip(), 4), (2, 0, 0))

    def testCheckSyntax(self):
        """Check that application can handle correctly a whole file block"""
        self.assertEquals(self.pparser.checkSyntax(), None)

    def test_getTimeStamp(self):
        """Check loading for timestamps value(s)"""
        self.assertEquals(self.pparser._getTimeStamp("[00:00:00 000]"), "00:00:00 000")
        self.assertEquals(self.pparser._getTimeStamp("[+00:00:00 001]"), "+00:00:00 001")

    def test_loadData(self):
        """Test the loading of a complete commands datablock"""
        self.pparser._loadData()
        self.assertEquals(self.pparser.data["operations"][1]["commands"][2], "dummy = 'abc'")
예제 #2
0
def cheeseBoysInit():
    """Init of the engine"""    
    LOGLEVEL_CHOICES = ('ERROR','WARN','INFO', 'DEBUG')
    DARKNESS_CHOICES = ('on', 'off')
    usage = "usage: %prog [options] [arg]"
    p = optparse.OptionParser(usage=usage, description="Run the Cheese Boys game engine, or execute some other usefull utility instead if you give some of the options below.")
    p.add_option('--version', '-v', action='store_true', help='print software version then exit')
    p.add_option('--debug', '-d', action="store_true", help="Enable game debug mode (for develop and test purpose)")
    p.add_option('--logverbosity', '-l', default="WARN", action="store", choices=LOGLEVEL_CHOICES, help='set the game log verbosity, one of %s (default is ERROR)' % ",".join(LOGLEVEL_CHOICES), metavar="VERBOSITY")
    p.add_option('--tests', '-t', action='store_true', help='run all game unittests') 
    p.add_option('--fullscreen', '-f', action='store_true', help='load the game in fullscreen mode')
    p.add_option("--parse", "-p" , action='store_true', help=("parse a data file for dinamically change the content. See also -cbp options"
                                                              "You can also use the --timestamp option to begin begin operation only after found a specific timestamp"))
    p.add_option("--cbp", "-c" , dest="cbp_filename", help="Must be used in combination of -p option. Parse a .cbp file to change absolute timestamps with dinamical ones. ", metavar="FILE")
    p.add_option("--timestamp", dest="timestamp", help="Use this for other options that can require timestamp values", metavar="TIMESTAMP")

    options, arguments = p.parse_args()
    
    if options.version:
        print "Cheese Boys version %s" % cblocals.__version__
        exit()

    if options.logverbosity=="ERROR":
        logging.getLogger().setLevel(logging.ERROR)
    elif options.logverbosity=="WARN":
        logging.getLogger().setLevel(logging.WARN)
    elif options.logverbosity=="INFO":
        logging.getLogger().setLevel(logging.INFO)
    elif options.logverbosity=="DEBUG":
        logging.getLogger().setLevel(logging.DEBUG)
    else:
        print "error: %s is an invalid option for --logverbosity option, use one of %s" % (options.logverbosity, ",".join(LOGLEVEL_CHOICES))  
        sys.exit(1)

    if options.tests:
        tests()
        exit()

    if options.fullscreen:
        cblocals.FULLSCREEN = True

    if options.parse:
        if not options.cbp_filename:
            print "error: The --parse parameter need also the use of --cbp option."
            sys.exit(1)
        else:
            from cheeseboys.presentation.presentation_parser import PresentationParser
            outFile = None
            if arguments:
                outFile = arguments[0]
            PresentationParser.replaceCbpFileAbsoluteTimestamps(options.cbp_filename, options.timestamp, outFile)
            sys.exit(0)

    cblocals.object_registry = UniqueObjectRegistry()

    # init of some pygame graphics stuff
    pygame.init()
    screen = handleFullScreen()
    pygame.display.set_icon(utils.load_image("cheese_icon.gif",simpleLoad=True))
    gettext.install('cheeseboys', 'data/i18n', unicode=1)

    if cblocals.SHADOW:
        cblocals.shadow_image = utils.load_image("lightray_1.png", "shadows", simpleLoad=True)
        cblocals.shadow_image.set_alpha(0, RLEACCEL)
        cblocals.total_shadow_image_09 = utils.load_image("total_dark_09.png", "shadows", simpleLoad=True)
        #cblocals.total_shadow_image_09.set_alpha(0, RLEACCEL)
        cblocals.total_shadow_image_05 = utils.load_image("total_dark_05.png", "shadows", simpleLoad=True)
        #cblocals.total_shadow_image_05.set_alpha(0, RLEACCEL)

    cblocals.default_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 12)
    cblocals.font_mini = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 10)
    cblocals.default_font_big = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 16)
    cblocals.speech_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_FONT), 14)
    cblocals.leveltext_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.DEFAULT_LEVELTEXT_FONT), 24)
    cblocals.main_title_font = pygame.font.Font("%s/%s" % (cblocals.FONTS_DIR_PATH, cblocals.MAIN_TITLE_FONT), 72)
예제 #3
0
 def setUp(self):
     CheeseBoysTestCase.setUp(self)
     self.pparser = PresentationParser("dummy")
     # init parameter, as I will never call .open()
     self.pparser._text = FAKE_CBP_FILE
     self.pparser._lines = self.pparser._text.split("\n")