def test_openFileWithToolParameters_realData(self, mock_serialdev,
                                                 mock_readAll, mock_cartesian):

        # Preparing for the test
        try:
            os.remove('generic_tool.json')
        except:
            pass

        with open('generic_tool.json', 'w') as f:
            f.write(json.dumps({'a': 'b'}))

        mock_readAll.return_value = "Welcome returned from the device"
        ar = cartesian.arnie('COM1', 'COM2')
        generic_tool = tools.tool(ar,
                                  'COM3',
                                  tool_name='generic_tool',
                                  welcome_message='welcome')

        # Test
        result_data_dict = generic_tool.openFileWithToolParameters(
            'generic_tool.json')
        self.assertEqual(result_data_dict, {'a': 'b'})
        self.assertEqual(generic_tool.tool_data, {
            'a': 'b',
            'name': 'generic_tool',
            'welcome_message': 'welcome'
        })

        # Cleaning up after the test
        try:
            os.remove('generic_tool.json')
        except:
            pass
 def test_genericToolEmptyInit__properRackName(self, mock_serialdev,
                                               mock_readAll, mock_cartesian,
                                               mock_racks):
     mock_readAll.return_value = "Welcome returned from the device"
     ar = cartesian.arnie('COM1', 'COM2')
     generic_tool = tools.tool(ar,
                               'COM3',
                               tool_name='generic_tool',
                               welcome_message='welcome')
     mock_racks.assert_called_with(rack_name='generic_tool_rack',
                                   rack_type='generic_tool_rack')
 def test_genericToolEmptyInit__rack_data(self, mock_serialdev,
                                          mock_readAll, mock_cartesian):
     mock_readAll.return_value = "Welcome returned from the device"
     ar = cartesian.arnie('COM1', 'COM2')
     generic_tool = tools.tool(ar,
                               'COM3',
                               tool_name='generic_tool',
                               welcome_message='welcome')
     rack_data = generic_tool.rack.rack_data
     self.assertIn('name', rack_data)
     self.assertNotIn('somerandomnamewhichwillneveroccurinreallife',
                      rack_data)
 def test_genericToolEmptyInit__tool_data(self, mock_serialdev,
                                          mock_readAll, mock_cartesian):
     mock_readAll.return_value = "Welcome returned from the device"
     ar = cartesian.arnie('COM1', 'COM2')
     generic_tool = tools.tool(ar,
                               'COM3',
                               tool_name='generic_tool',
                               welcome_message='welcome')
     tool_data = generic_tool.tool_data
     self.assertEqual(tool_data, {
         'name': 'generic_tool',
         'welcome_message': 'welcome'
     })
 def test_genericToolEmptyInit(self, mock_serialdev, mock_readAll,
                               mock_cartesian):
     mock_readAll.return_value = "Welcome returned from the device"
     ar = cartesian.arnie('COM1', 'COM2')
     generic_tool = tools.tool(ar,
                               'COM3',
                               tool_name='generic_tool',
                               welcome_message='welcome')
     mock_readAll.assert_called()
     self.assertEqual(generic_tool.actual_welcome_message,
                      "Welcome returned from the device")
     mock_cartesian.assert_called()
     mock_serialdev.assert_called()
     mock_serialdev.assert_called_with('COM3', 115200, timeout=0.1)
 def __init__(self):
     self.health = 10
     self.water = 10
     self.hunger = 10
     self.difficulty = "N/A"
     self.temperature = 98.6
     self.homeostasis = 98.6
     self.alive = True
     self.decisionsMade = 0
     self.score = 0
     self.placesVisited = []
     self.currentPosition = "Start"
     self.decidedLocation = 0
     backpack = tool("backpack", "Storage")
     self.inventory = [backpack]
Exemple #7
0
 def splice_cmd(self, env, script_name, fp):
     global execmd
     if env == "Outside":
         execmd = dao().get_script_info(script_name).script_content_o
     elif env == "Intranet":
         execmd = dao().get_script_info(script_name).script_content_n
         execmd = execmd.format(fp)
         if script_name == "ABtest":
             execmd = "{}{}{}".format(
                 tool().replace_file(
                     "/usr/local/webdata/php/{}/fun/batch/Betatest".format(
                         fp), "mysql:host=192.168.100.60;",
                     "mysql:host=192.168.100.78;", "config.php"), "\n",
                 execmd)
     self.logger.info("execmd:{}".format(execmd))
     return execmd
 def test_save(self, mock_serialdev, mock_readAll, mock_cartesian,
               mock_json_dumps):
     mock_readAll.return_value = "Welcome returned from the device"
     ar = cartesian.arnie('COM1', 'COM2')
     generic_tool = tools.tool(ar,
                               'COM3',
                               tool_name='generic_tool',
                               welcome_message='welcome')
     mock_json_dumps.return_value = "{'a': 'b'}"
     generic_tool.save()
     mock_json_dumps.assert_called_with({
         'name': 'generic_tool',
         'welcome_message': 'welcome'
     })
     try:
         os.remove('generic_tool.json')
     except:
         pass
 def setDifficulty(self, difficulty):
     if difficulty == 0:
         self.difficulty = "Easy"
         self.health = 20
         self.water = 20
         self.hunger = 20
         knife = tool("knife", "Killing")
         self.changeInventory(knife, True)
     elif difficulty == 1:
         self.difficulty = "Medium"
         self.health = 10
         self.water = 10
         self.hunger = 10
     elif difficulty == 2:
         self.difficulty = "Hard"
         self.health = 5
         self.water = 5
         self.hunger = 5
    def test_obtainSlotCenter(self, mock_serialdev, mock_readAll,
                              mock_cartesian):
        try:
            os.remove('generic_tool_rack.json')
        except:
            pass

        mock_readAll.return_value = "Welcome returned from the device"
        ar = cartesian.arnie('COM1', 'COM2')
        generic_tool = tools.tool(ar,
                                  'COM3',
                                  tool_name='generic_tool',
                                  welcome_message='welcome')
        generic_tool.rack.overwriteSlot(1, 0)
        slot_center = generic_tool.rack.getSavedSlotCenter()
        self.assertGreater(slot_center[0], 230)
        self.assertLess(slot_center[0], 260)
        self.assertGreater(slot_center[1], 50)
        self.assertLess(slot_center[1], 80)
        self.assertGreater(slot_center[2], 500)
        self.assertLess(slot_center[2], 700)
Exemple #11
0
    def get_table_info(self, name):
        table_info = []
        if name[0] == None:
            script_data = dao().get_all_script_info()
        else:
            script_data = dao().search(name[0])

        for index in range(script_data.__len__()):
            item = {}
            tem = script_data[index].get_all()
            item["ScriptName"] = tem["script_name"]
            item["ScriptInfo"] = tem["script_info"]
            item["ScriptStatus"] = self.change_status_to_chinese(
                tem["script_status"])
            item["scriptdetail"] = tem["script_detail"]
            item["script_content_n"] = tem["script_content_n"].replace(
                "php /usr/local/webdata/php/{}/", "")
            item["script_content_o"] = tem["script_content_o"].replace(
                "php /usr/local/webdata/", "")

            table_info.append(tool().encode_fac(item))
        table_info = self.tool().cnsort(table_info)
        return table_info
Exemple #12
0
difficulties = ["easy", "medium", "hard"]
difficulty = p.getTextInput(difficulties, 1, checkDamage = True)
p.setDifficulty(difficulty)
print(bigLetter.renderText(difficulties[difficulty]))
p.printStats()
a = "\n\nOk, now let’s see what happened to you."
if choice == 0:
    b = "You slowly reach over and pick up the stick."
    c = "The rattlesnake has started rattling its tail, it is warning you to back off. "
    d = "You jab the 1-foot long stick towards the snake’s face."
    e = "The snake stays right where it is, its rattling sound grows louder. The snake is surely going to jump at you!"
    f = "But no, you swing the stick into the snake’s mouth and smack its head on the ground."
    g = "Now you can safely leave the area."
    h = "You better hold on to the stick, sticks are rare in the desert."
    p.move("away from the snake")
    stick = tool("stick", "Killing", 10)
    p.changeInventory(stick, True)
    p.storyTelling([a,b,c,d,e,f,g,h],3)

elif choice == 1:
    b = "The snake is right in front of you."
    c = "You look behind you to see if there are any obstructions ..."
    d = "and you slowly back away and then quickly turn around and run to safety."
    p.move("away from the snake")
    p.storyTelling([a,b,c,d],3)

elif choice == 2:
    d = "The snake is slowly inching towards you. "
    e = "You try not to move but the snake can still see you."
    f = "Out of nowhere, a chipmunk lunges into the air and the snake pounces on it."
    g = "You quickly run away to safety."
    def findFood(self):
        a = "In the desert, there are two different sources of food."
        b = "Plants and animals"
        c = "We have to choice a group to focus on"
        l = "plants"
        m = "animals"
        self.storyTelling([a, b, c])
        choice = self.getTextInput([l, m])
        if choice == 0:
            self.findWaterPlant()
        elif choice == 1:
            a = "\nYou can see a few different animals around you."
            b = "There are lizards, snakes, insects, and gerbils."
            c = "There are also some predators so you must be careful of what you choose."
            self.storyTelling([a, b, c])
            print("Choose where you try and get food.")
            a = "lizards"
            b = "insects"
            c = "gerbils"
            choice = self.getTextInput([a, b, c])
            if choice == 0:
                a = "Looks like we are looking for lizards. "
                b = "First, we will have to catch a lizard."
                c = "Then we have to kill it."
                d = "Then we need to cut it and eat it"
                e = "You need a tool to kill it."
                self.storyTelling([a, b, c, d, e])
                canUse = self.useTool("Killing")

                if not canUse:
                    print("You don't have any tools for this. Try again.")
                    return

                chance = random.randint(1, 10)
                if chance == 1:
                    a = "You damaged yourself while trying to get the lizards."
                    b = f"It took you {random.randint(1,20)} attempts to kill a lizard"
                    c = "The lizard has been added to your inventory. To eat it type use."
                    self.health -= 2
                    self.score -= 10
                    self.storyTelling([a, b, c])
                    lizard = tool("lizard", "Eating", 1)
                    self.changeInventory(lizard, True)

                elif 1 < choice <= 3:
                    a = "You were unable to catch a lizard."
                    b = "You lost 2 hunger points."
                    self.hunger -= 2
                    self.score -= 10
                    self.storyTelling([a, b])

                else:
                    b = f"It took you {random.randint(1,20)} attempts to kill a lizard"
                    c = "The lizard has been added to your inventory. To eat it type use."
                    self.storyTelling([b, c])
                    lizard = tool("lizard", "Eating", 1)
                    self.changeInventory(lizard, True)
                    self.score += 50

            elif choice == 1:
                a = "Looks like we are looking for insects"
                b = "Insects are easy to find, but they aren't very nutritous."
                c = "We will look near exposed flowers to find them"
                self.storyTelling([a, b, c])
                print("You can catch insects easily.")
                print("But you need a tool to kill it.")
                canUse = self.useTool("Killing")

                if not canUse:
                    print("You don't have any tools for this. Try again.")
                    return
                a = f"You were able to kill {random.randint(10,30)} insects."
                chance = random.randint(0, 2)
                if choice == 0:
                    c = "A scorpion injected venom into you."
                    d = "You lose 2 health points"
                    self.health -= 2
                    self.score -= 10
                    e = "But you still eat all of your insects"
                    self.hunger += 2
                    self.water += 2
                    self.temperature -= 1
                    self.score += 50
                    self.storyTelling([a, b, c, d, e])
                elif choice == 1:
                    c = "A snake steals all your insects from your backpack"
                    self.storyTelling([a, b, c])
                elif choice == 2:
                    c = "You can't store the insects."
                    e = "You eat them now."
                    d = "You gain 2 water points and 1 hunger point."
                    self.storyTelling([a, b, c, e, d])
                    self.hunger += 2
                    self.water += 2
                    self.temperature -= 1
                    self.score += 50

            elif choice == 2:
                a = "Looks like we are looking for gerbils"
                b = "Gerbils can be found all over the desert."
                c = "But they are really quick and hard to catch"
                self.storyTelling([a, b, c])
                print("You need to run to try and catch them.")
                print("You need a tool to kill them.")
                canUse = self.useTool("Killing")

                if not canUse:
                    print("You don't have any tools for this. Try again.")
                    return
                a = "You were able to grab a gerbil."
                b = "You store it in your backpack"
                chance = random.randint(0, 2)
                if choice == 0:
                    c = "You injured yourself while running after the gerbil."
                    d = "You lose 2 health points"
                    self.health -= 2
                    self.score -= 10
                    self.storyTelling([a, b, c, d])
                elif choice == 1:
                    c = "While you were away,"
                    d = "a snake slithered into your backpack and took your gerbil"
                    self.storyTelling([a, b, c, d])
                elif choice == 2:
                    c = "You know have a gerbil to use"

                    self.storyTelling([a, b, c])
                    self.score += 50
                    gerbil = tool("gerbil", "Eating", 1)
                    self.inventory.append(gerbil)