def testDrawIcon(self):
        absPath = path.abspath("symbol-solenoid.svg")
        icon = Icon(absPath)
        self.assertTrue(icon.isCorrect())

        blankSVGpath = 'blank.svg'
        svgTree = etree.parse(blankSVGpath)
        svgRoot = svgTree.getroot()
        svgFile = svg.SVG()
        svgFile.setSvg(svgRoot)

        icon.updateSvg()
        symbolsNode = svgFile.getSymbolsNode()
        self.assertNotEqual(symbolsNode, None)
        iconNode = svgFile.getElementById("symbol-solenoid", symbolsNode)
        self.assertNotEqual(iconNode, None)
        self.assertEqual(iconNode.attrib["style"], "display:inline")
        self.assertEqual(iconNode.tag, "g")

        imageNode = iconNode[0]
        self.assertEqual(imageNode.tag, "image")
        self.assertEqual(imageNode.attrib["{http://www.w3.org/1999/xlink}href"], absPath)
        self.assertEqual(imageNode.attrib["x"], "0")
        self.assertEqual(imageNode.attrib["y"], "0")
        self.assertEqual(imageNode.attrib["width"], "30")
        self.assertEqual(imageNode.attrib["height"], "30")
    def testDrawIcon(self):
        absPath = path.abspath("symbol-solenoid.svg")
        icon = Icon(absPath)
        self.assertTrue(icon.isCorrect())

        blankSVGpath = "blank.svg"
        svgTree = etree.parse(blankSVGpath)
        svgRoot = svgTree.getroot()
        svgFile = svg.SVG()
        svgFile.setSvg(svgRoot)

        icon.updateSvg()
        symbolsNode = svgFile.getSymbolsNode()
        self.assertNotEqual(symbolsNode, None)
        iconNode = svgFile.getElementById("symbol-solenoid", symbolsNode)
        self.assertNotEqual(iconNode, None)
        self.assertEqual(iconNode.attrib["style"], "display:inline")
        self.assertEqual(iconNode.tag, "g")

        imageNode = iconNode[0]
        self.assertEqual(imageNode.tag, "image")
        self.assertEqual(imageNode.attrib["{http://www.w3.org/1999/xlink}href"], absPath)
        self.assertEqual(imageNode.attrib["x"], "0")
        self.assertEqual(imageNode.attrib["y"], "0")
        self.assertEqual(imageNode.attrib["width"], "30")
        self.assertEqual(imageNode.attrib["height"], "30")
 def testCutExtension(self):
     icon = Icon("/icon/name.jpg")
     self.assertEqual(icon.name, "name")
     icon.name = "foo.Bar"
     icon.cutExtensionInName()
     self.assertEqual(icon.name, "foo")
     icon.name = "TE5T"
     self.assertEqual(icon.name, "TE5T")
Exemplo n.º 4
0
    def setUp(self):
        """Create a Test Icon and start pygame."""
        pygame.init()
        self.test_text_icon = Icon('test icon', GameWindow.BLACK,
                                   GameWindow.WHITE, Point(0, 0), (10, 10))

        self.test_vertex_icon = Icon('vertex icon', GameWindow.BLACK,
                                     GameWindow.WHITE, Point(0, 0), (10, 10))

        self.test_vertex_icon.vertices = [(10, 10), (-10, -10), (0, 0)]
Exemplo n.º 5
0
    def testCheckingConditions(self):
        deviceWithoutIcon = Device("A/B/C", None, None)
        deviceWithoutIcon.section = True
        with self.assertRaises(Exception):
            deviceWithoutIcon.checkNecessaryConditions()

        deviceWithoutSection = Device("D/E/F", Icon("test"), None)
        with self.assertRaises(Exception):
            deviceWithoutSection.checkNecessaryConditions()

        deviceWithWrongSubsystem = Device("GHI", Icon("test"), None)
        deviceWithWrongSubsystem.section = True
        with self.assertRaises(Exception):
            deviceWithWrongSubsystem.checkNecessaryConditions()
Exemplo n.º 6
0
 def testConfiguration(self):
     coord = (12, 13.901)
     icon = Icon("test/path")
     device = Device("name", icon, coord)
     self.assertEqual(device.icon, icon)
     self.assertEqual(device.realCoordinates, coord)
     self.assertEqual(device.name, "name")
Exemplo n.º 7
0
    def _convert_memory_to_icons(self, beebot_memory):
        """Convert the BeeBot memory into Icons."""
        # The location to draw the first Icon in the CommandLog.
        location = self.screen_location

        if self.horizontal:
            # Make the next Icon appear right of the current one.
            increment = (self.icon_size[0], 0)
        else:
            # Make the next Icon appear below the current one.
            increment = (0, self.icon_size[1])

        for index, entry in enumerate(beebot_memory):
            # Convert Events into Icon Arrows.
            text = self._event_type_to_text(entry.type)
            # Create a new Icon
            tmp_log = Icon(text, (0, 0, 0), (255, 255, 255), location,
                           self.icon_size)

            # Add the Icon to the CommandLog.
            # We need to provide a key here because instances of CommandLog
            # will have multiple Icons with the same text (i.e.
            # "Forward", "Backward", "Turn Left", "Turn Right")
            # that would otherwise override each other.
            self.add(tmp_log, key=index)

            # Put the next Icon in the right place
            location = location + increment
 def changeDeviceIcon(self):
     iconPath = self.deviceIcon.getSelectedIcon()
     if self.device.icon is not None:
         self.device.icon.path = iconPath
     else:
         newIcon = Icon(iconPath)
         self.device.icon = newIcon
Exemplo n.º 9
0
    def setUp(self):
        """Initiate pygame and create a test IconGroup and Icons."""
        # Initiate pygame so we can use fonts
        pygame.init()

        # Create a test IconGroup
        self.test_icon_group = IconGroup()

        # Create some test Icons
        self.test_icon = Icon("Test", (0, 0, 0), (255, 255, 255), (0, 0),
                              (10, 10))
        self.other_icon = Icon("Other", (0, 0, 0), (255, 255, 255), (20, 20),
                               (10, 10))

        # Add those test Icons to the test IconGroup
        self.test_icon_group.add(self.other_icon)
        self.test_icon_group.add(self.test_icon)
Exemplo n.º 10
0
 def testNameUpdate(self):
     icon = Icon("/path/to/file123.jpg")
     self.assertEqual(icon.name, "file123")
     icon.path = "/other/path/imageFoo"
     self.assertNotEqual(icon.name, "imageFoo")
     icon.updateName()
     self.assertEqual(icon.name, "imageFoo")
     icon.path = "/another/iMg.gif"
     icon.updateName()
     self.assertEqual(icon.name, "iMg")
     self.assertEqual(icon.path, "/another/iMg.gif")
Exemplo n.º 11
0
class TestIcon(unittest.TestCase):
    """This class unit tests the Icon class."""
    def setUp(self):
        """Create a Test Icon and start pygame."""
        pygame.init()
        self.test_text_icon = Icon('test icon', GameWindow.BLACK,
                                   GameWindow.WHITE, Point(0, 0), (10, 10))

        self.test_vertex_icon = Icon('vertex icon', GameWindow.BLACK,
                                     GameWindow.WHITE, Point(0, 0), (10, 10))

        self.test_vertex_icon.vertices = [(10, 10), (-10, -10), (0, 0)]

    @classmethod
    def test_init(cls):
        """Test the init method of the Icon class."""
        _unused_icon = Icon('test icon', GameWindow.BLACK, GameWindow.WHITE,
                            Point(0, 0), (10, 10))

    def test_get_vertex_list(self):
        """Test the _get_vertex_list method."""
        input_list = [Point(0, 0), Point(5, 0), Point(0, -5)]
        center = (10, 10)

        # _get_vertex_list(input_list, center_x, center_y) should map
        # (0,0) of the input_list to center_x and center_y (and all other
        # points accordingly)
        expected_output = [Point(10, 10), Point(15, 10), Point(10, 5)]

        # We need to use an instance of the Icon class
        # to call the _get_vertex_list method
        output = self.test_text_icon._get_vertex_list(input_list, center)

        self.assertEqual(expected_output, output)

    def test_display(self):
        """
        Test the display method of a Icon.

        All this really does is make sure the method executes correctly.
        If the method call errors, the test will fail.
        """
        # Create a test screen to dsiplay things on
        test_screen = pygame.display.set_mode((1500, 1500))

        # Attempt to display the test text Icon
        self.test_text_icon.display(test_screen)

        # Attempt to display the test vertex Icon
        self.test_vertex_icon.display(test_screen)

        # Make the test text Icon not displayed
        self.test_text_icon.displayed = False
        # This will test the branch of code for when you attempt to
        # display a non displayed Icon
        self.test_text_icon.display(test_screen)
Exemplo n.º 12
0
 def testNameUpdate(self):
     icon = Icon("/path/to/file123.jpg")
     self.assertEqual(icon.name, "file123")
     icon.path = "/other/path/imageFoo"
     self.assertNotEqual(icon.name, "imageFoo")
     icon.updateName()
     self.assertEqual(icon.name, "imageFoo")
     icon.path = "/another/iMg.gif"
     icon.updateName()
     self.assertEqual(icon.name, "iMg")
     self.assertEqual(icon.path, "/another/iMg.gif")
Exemplo n.º 13
0
 def testCutExtension(self):
     icon = Icon("/icon/name.jpg")
     self.assertEqual(icon.name, "name")
     icon.name = "foo.Bar"
     icon.cutExtensionInName()
     self.assertEqual(icon.name, "foo")
     icon.name = "TE5T"
     self.assertEqual(icon.name, "TE5T")
Exemplo n.º 14
0
    def test_add(self):
        """
        Test the add method when it uses a specific key.

        The default key behaviour is tested indirectly in setUp().
        """
        new_icon = Icon("New", (0, 0, 0), (255, 255, 255), (30, 30), (10, 10))

        # Add new_icon to the test_icon_group, but use a specific key.
        self.test_icon_group.add(new_icon, key="Old")

        # Assert the new_icon was stored under the correct key.
        self.assertIs(self.test_icon_group.icons["Old"], new_icon)
        # Assert that there is nothing stored under the "New" key,
        # which is what would happen if new_icon
        # was added with no specific key.
        self.assertFalse("New" in self.test_icon_group.icons.keys())
Exemplo n.º 15
0
    def testDrawDevice(self):
        icon = Icon("symbol-quadrupole.svg")
        device = Device("I-K01/VAC/I-K01CAB05-VAC-IPCU1", icon, (113, 122))
        linac = Linac()
        linac.addSection("I-K01")
        linac.addDevice(device)

        blankSVGpath = 'blank.svg'
        svgTree = etree.parse(blankSVGpath)
        svgRoot = svgTree.getroot()
        svgFile = svg.SVG()
        svgFile.setSvg(svgRoot)

        device.updateSvg()
        vacNode = svgFile.getSubsystemZoomNode("VAC")
        deviceNode = svgFile.getElementById("ik01vacik01cab05vacipcu1",
                                            vacNode)
        self.assertEqual(
            deviceNode.attrib["{http://www.w3.org/1999/xlink}href"],
            "#symbol-quadrupole")
        descriptionNode = svgFile.getElementById(
            "ik01vacik01cab05vacipcu1Desc", deviceNode)
        self.assertEqual(descriptionNode.text,
                         "device=I-K01/VAC/I-K01CAB05-VAC-IPCU1")
Exemplo n.º 16
0
 def testInitialization(self):
     icon = Icon("path/to/file.png")
     self.assertEqual(icon.name, "file")
     self.assertEqual(icon.path, "path/to/file.png")
     self.assertEqual(icon.coordinates, (0,0))
Exemplo n.º 17
0
 def test_init(cls):
     """Test the init method of the Icon class."""
     _unused_icon = Icon('test icon', GameWindow.BLACK, GameWindow.WHITE,
                         Point(0, 0), (10, 10))
Exemplo n.º 18
0
 def testIconCorrect(self):
     icon = Icon("path/to/file.png")
     self.assertFalse(icon.isCorrect())
     icon.path = "blank.svg"
     self.assertTrue(icon.isCorrect())
Exemplo n.º 19
0
 def testIconCorrect(self):
     icon = Icon("path/to/file.png")
     self.assertFalse(icon.isCorrect())
     icon.path = "blank.svg"
     self.assertTrue(icon.isCorrect())