예제 #1
0
    def drop(self, player, location):
        config = self.get_config()
        location.add_inventory_item(self.name, config)
        player.remove_inventory_item(self.name)

        utils.print_message("You drop the '{}'".format(colour.green(
            self.name)))
예제 #2
0
def on_message(client, userdata, msg):  #  triggers on an update
    print('topic is: ' + str(msg.topic))
    print('message is: ' + str(msg.payload).replace("b'", '').replace("'", ''))
    command = str(msg.payload).replace("b'", '').replace("'", '').lower()
    if command == str('1'):  #  runs dummy file
        dummy.run()
    elif command == str(
            '2'):  #  copy this statement and adjust for each script
        dummy2.run()
    elif "blue" in command:
        colour.blue()
    elif "red" in command:
        colour.red()
    elif "green" in command:
        colour.green()
    elif "clear" in command:
        colour.clear()
    print('')
예제 #3
0
    def open(self, context):
        if (utils.has_attribute(self._config, "openable")):
            if (utils.has_attribute(self._config, "locked")):
                utils.print_message("Item '{}' is locked.".format(
                    colour.red(self.name)))
                return
            if ("inside" in self._config):
                items = self._config.pop("inside", None)
                self._config["revealed"] = items
                item_name = sorted(items)[
                    0]  # only allow 1 item - inside stuff
                self.add_inventory_items(items)
                if (len(items) > 0):
                    #if(utils.has_attribute(self._config, "door")):
                    if ("opened" in self._config):
                        utils.print_messages(self._config["opened"])
                    ## remove doors after open
                    if (utils.has_attribute(self._config, "door")):
                        context.remove_inventory_item(self.name)

                    if (utils.has_attribute(self._config, "door")):
                        utils.print_message(
                            "You see the '{}' through the '{}'".format(
                                colour.green(item_name),
                                colour.green(self.name)))
                    else:
                        utils.print_message(
                            "You see the '{}' in the '{}'".format(
                                colour.green(item_name),
                                colour.green(self.name)))
                if (self.has_inventory()):
                    context.add_inventory_items(self.get_inventory_items())
        else:
            if ("taken" in self._config and "inside" in self._config["taken"]):
                utils.print_message("{}".format(
                    colour.red(
                        "You cannot open this item until it has been taken.")))
                utils.print_message("Hint: {}".format(
                    colour.green(
                        "Taking items show more details - You may see more detail when examined, and be able to open it!"
                    )))
            return
            utils.print_message("{}".format(
                colour.red("You cannot open this item.")))
예제 #4
0
def createTestSuite(engine):

    # Run all tests
    results = engine.run()

    #Posting Results to Server
    #params = {
    #    "email": os.environ["APP_EMAIL"],
    #    "podId": os.environ["POD_ID"],
    #    "results" : json.dumps(results)
    #}

    #result = requests.post(
    #    "https://3000-ab155182-05d4-4bf5-b47e-2b757b153877.ws-eu01.gitpod.io/api/test-result",
    #    # "https://python-code-test-server.herokuapp.com/api/test-result",
    #    data=params
    #    )

    print(f"Running tests for {engine.label}")
    for result in results:
        print("")
        if (result["status"] == "passed"):
            textGreen()
            print(u'\u2714', end=" ")
            textReset()
            print("{0}......{1}".format(result["name"], green("Passed")))
        else:
            textRed()
            print(u'\u2718', end=" ")
            textReset()
            print("{0}.....{1}".format(result["name"], red("Failed")))
            print("\tExpected")
            print("\t========")
            print("\t", result['expected'])
            print("")

            print("\tActual")
            print("\t========")
            print("\t", result['actual'])

        textReset()

    success, fail = agg(results)

    progress = (float(success) / len(engine.getTests()) * 100.0)
    print(f"{success} Successes")
    print(f"{fail} Fails")
    print(f"{engine.label} is {progress:.2f} % complete.")
    print("")
    print("")

    return results, success, fail, progress
예제 #5
0
 def move(self, context):
     if (utils.has_attribute(self._config, "moveable")):
         if ("inside" in self._config):
             items = self._config.pop("inside", None)
             self._config["revealed"] = items
             item_name = sorted(items)[
                 0]  # only allow 1 item - inside stuff
             self.add_inventory_items(items)
             if (len(items) > 0):
                 if ("moved" in self._config):
                     utils.print_messages(self._config["moved"])
                 utils.print_message(
                     "You see a '{}' after moving the '{}'".format(
                         colour.green(item_name), colour.green(self.name)))
             if (self.has_inventory()):
                 context.add_inventory_items(self.get_inventory_items())
         else:
             utils.print_message("You moved the '{}'".format(
                 colour.green(self.name)))
     else:
         utils.print_message("{}".format(
             colour.red("You cannot move this item.")))
예제 #6
0
 def take(self, location, player):
     if ("attributes" in self._config
             and "takeable" in self._config["attributes"]):
         config = self.get_config()
         player.add_inventory_item(self.name, config)
         location.remove_inventory_item(self.name)
         if ("taken" in config):
             taken = config.pop("taken")
             for key in taken:
                 config[key] = taken[key]
         utils.print_message("You take the '{}'".format(
             colour.green(self.name)))
     else:
         utils.print_message("You cannot take '{}'.".format(
             colour.red(self.name)))
예제 #7
0
def vermodCheck(filePath, versions, testNum):
    import colour
    exPrefix = colour.red('FAILURE') + ', Test #' + str(testNum) + ': '
    if len(versions) != 4:
        raise Exception(exPrefix + 'Versions list is of the wrong size!')
    vMajor = str(versions[0])
    vMinor = str(versions[1])
    vRelease = str(versions[2])
    vBuild = str(versions[3])
    vString = vMajor + '.' + vMinor + '.' + vRelease + '.' + vBuild
    f = open(filePath, 'r')
    text = f.read()
    from re import search
    if(search('_VERSION_STRING "' + vString + '"', text) == None
    or search('_VERSION_MAJOR\\s+' + vMajor, text) == None
    or search('_VERSION_MINOR\\s+' + vMinor, text) == None
    or search('_VERSION_RELEASE\\s+' + vRelease, text) == None
    or search('_VERSION_BUILD\\s+' + vBuild, text) == None):
        raise Exception(exPrefix + 'One or more definitions were missing ' +
            'or invalid.')
    print(colour.green('SUCCESS') + ', Test #' + str(testNum))
예제 #8
0
def get_inventory_display(items):
    visible = []

    for item_name in sorted(items):
        item = items[item_name]
        config = item
        if (not type(item) == dict):
            config = item.get_config()
        if (has_attribute(config, "room")):
            visible.append("'{}'".format(colour.yellow(item_name)))
        elif (has_attribute(config, "locked")):
            visible.append("'{}'".format(colour.red(item_name)))
        elif (has_attribute(config, "switchable")):
            visible.append("'{}'".format(colour.cyan(item_name)))
        # elif(has_attribute(config, "takeable")):
        #     visible.append("'{}'".format(colour.cyan(item_name)))
        elif (has_attribute(config, "container")):
            visible.append("'{}'".format(colour.cyan(item_name)))
        elif (has_attribute(config, "openable")):
            visible.append("'{}'".format(colour.cyan(item_name)))
        else:
            visible.append("'{}'".format(colour.green(item_name)))
            #visible.append("'{}'".format(item_name))
    formatted = []
    part = []
    max_per_line = 5
    count = 1
    for display in visible:
        if (count % max_per_line == 0):
            part.append(display)
            formatted.append(", ".join(part))
            part = []
        else:
            part.append(display)
        count += 1
    formatted.append(", ".join(part))

    return "\n  ".join(formatted)
예제 #9
0
            sys.exit(0)

    id = os.environ.get('CHALLENGE_ID')
    title = os.environ.get("CHALLENGE_TITLE")
    email = os.environ.get("EMAIL")

    print(f"Getting Files for Challenge ID {id} from DB.")
    print("")

    r = requests.get(
        f"https://cs-revise.leroysalih.vercel.app/api/challenge/{id}")
    obj = json.loads(r.text)

    f = open("./main.py", "w")
    f.write(obj['main'])
    f.close()

    f = open("./tests/maintestengine.py", "w")
    f.write(obj['test'])
    f.close()

    f = open("./README.md", "w")
    f.write(obj['README'])
    f.close()

    f = open("./env", "w")
    f.write([id, title, email])
    f.close()

    print(green("Files generated"))
예제 #10
0
from colour import blue, green

blue()

print("---")

# error
# yellow()

print("---")

# works:
green()

print("---")

예제 #11
0
def main(args):
    # Define our test suite source files
    from os import mkdir, path
    sampleSrcPath = path.join('test', 'sample.h')
    testDirPath = path.join('build', 'test')
    sampleDstPath = path.join(testDirPath, 'sample.h')
    # Make our test suite's directories
    from shutil import copy2, rmtree
    try:
        rmtree('build')
    except:
        pass
    mkdir('build', 0o755)
    mkdir(testDirPath, 0o755)
    # Copy over our test suite sources
    copy2(sampleSrcPath, testDirPath)
    # Execute the tests!
    # Suite A: VersionMod script
    vermodCheck(sampleDstPath, [1, 1, 1, 1], 1)
    import versionmod
    versionmod.main(['versionmod.py', 'increment', 'major', sampleDstPath])
    vermodCheck(sampleDstPath, [2, 0, 0, 0], 2)
    versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath])
    vermodCheck(sampleDstPath, [2, 0, 0, 3], 3)
    versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath])
    vermodCheck(sampleDstPath, [2, 0, 1, 2], 4)
    versionmod.main(['versionmod.py', 'increment', 'minor', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'release', sampleDstPath])
    versionmod.main(['versionmod.py', 'increment', 'build', sampleDstPath])
    vermodCheck(sampleDstPath, [2, 1, 3, 1], 5)
    versionmod.main(['versionmod.py', 'increment', 'major', sampleDstPath])
    vermodCheck(sampleDstPath, [3, 0, 0, 0], 6)
    import colour
    print(colour.green('versionmod.py has passed testing.'))
    # Suite B: CopyDeps script
    exprefix = colour.red('FAILURE') + ', Test #7: '
    from os import getcwd, listdir, path
    srcDir = path.join(getcwd(), 'test', 'deps')
    dstDir = path.join(getcwd(), 'build', 'test')
    import copydeps
    if(copydeps.main(['copydeps.py', srcDir, dstDir, '64', 'release'])
    != 0):
        raise Exception(exprefix + 'CopyDeps program failed testing.')
    assets = listdir(path.join(srcDir, 'assets', 'release'))
    for asset in assets:
        if path.isfile(asset) == False:
            continue
        bname = path.basename(asset)
        if path.isfile(path.join(dstDir, bname)) == False:
            raise Exception(exprefix + 'Asset file "' + bname + '" was ' +
                'not copied into the destination directory.')
    libs = listdir(path.join(srcDir, 'lib64', 'release'))
    for lib in libs:
        if path.isfile(lib) == False:
            continue
        bname = path.basename(lib)
        if path.isfile(path.join(dstDir, bname)) == False:
            raise Exception(exprefix + 'Library file "' + bname + '" was' +
                ' not copied into the destination directory.')
    print(colour.green('copydeps.py has passed testing.') + '\n...')
    print(colour.green('All tests have passed.') + ' Exiting...')