Exemplo n.º 1
0
    def test_runpath_list(self):
        runpath_list = RunpathList('')

        self.assertEqual(len(runpath_list), 0)

        test_runpath_nodes = [RunpathNode(0, 0, "runpath0", "basename0"), RunpathNode(1, 0, "runpath1", "basename0")]

        runpath_node = test_runpath_nodes[0]
        runpath_list.add(runpath_node.realization, runpath_node.iteration, runpath_node.runpath, runpath_node.basename)

        self.assertEqual(len(runpath_list), 1)
        self.assertEqual(runpath_list[0], test_runpath_nodes[0])

        runpath_node = test_runpath_nodes[1]
        runpath_list.add(runpath_node.realization, runpath_node.iteration, runpath_node.runpath, runpath_node.basename)

        self.assertEqual(len(runpath_list), 2)
        self.assertEqual(runpath_list[1], test_runpath_nodes[1])

        for index, runpath_node in enumerate(runpath_list):
            self.assertEqual(runpath_node, test_runpath_nodes[index])


        runpath_list.clear()

        self.assertEqual(len(runpath_list), 0)
Exemplo n.º 2
0
    def test_collection(self):
        """Testing len, adding, getting (idx and slice), printing, clearing."""
        def path(idx):
            return 'path_%d' % idx

        def base(idx):
            return 'base_%d' % idx

        with TestAreaContext("runpath_list"):
            runpath_list = RunpathList("EXPORT.txt")
            runpath_list.add(3, 1, path(3), base(3))
            runpath_list.add(1, 1, path(1), base(1))
            runpath_list.add(2, 1, path(2), base(2))
            runpath_list.add(0, 0, path(0), base(0))
            runpath_list.add(3, 0, path(3), base(3))
            runpath_list.add(1, 0, path(1), base(1))
            runpath_list.add(2, 0, path(2), base(2))
            runpath_list.add(0, 1, path(0), base(0))

            self.assertEqual(8, len(runpath_list))
            pfx = 'RunpathList(size'  # the __repr__ function
            self.assertEqual(pfx, repr(runpath_list)[:len(pfx)])
            node2 = RunpathNode(2, 1, path(2), base(2))
            self.assertEqual(node2, runpath_list[2])

            node3 = RunpathNode(0, 0, path(0), base(0))
            node4 = RunpathNode(3, 0, path(3), base(3))
            node5 = RunpathNode(1, 0, path(1), base(1))
            node6 = RunpathNode(2, 0, path(2), base(2))
            nodeslice = [node3, node4, node5, node6]
            self.assertEqual(nodeslice, runpath_list[3:7])
            self.assertEqual(node6, runpath_list[-2])
            with self.assertRaises(TypeError):
                runpath_list["key"]
            with self.assertRaises(IndexError):
                runpath_list[12]

            runpath_list.clear()
            self.assertEqual(0, len(runpath_list))
            with self.assertRaises(IndexError):
                runpath_list[0]
            self.assertEqual('EXPORT.txt', runpath_list.getExportFile())