Exemplo n.º 1
0
    def test_sorted_export(self):
        with TestAreaContext("runpath_list_sorted"):
            runpath_list = RunpathList("EXPORT.txt")
            runpath_list.add( 3 , 1 , "path" , "base" )
            runpath_list.add( 1 , 1 , "path" , "base" )
            runpath_list.add( 2 , 1 , "path" , "base" )
            runpath_list.add( 0 , 0 , "path" , "base" )

            runpath_list.add( 3 , 0 , "path" , "base" )
            runpath_list.add( 1 , 0 , "path" , "base" )
            runpath_list.add( 2 , 0 , "path" , "base" )
            runpath_list.add( 0 , 1 , "path" , "base" )

            runpath_list.export( )

            path_list = []
            with open("EXPORT.txt") as f:
              for line in f.readlines():
                    tmp = line.split()
                    iens = int(tmp[0])
                    iteration = int(tmp[3])

                    path_list.append( (iens , iteration) )

            for iens in range(4):
                t0 = path_list[iens]
                t4 = path_list[iens + 4]
                self.assertEqual( t0[0] , iens )
                self.assertEqual( t4[0] , iens )

                self.assertEqual( t0[1] , 0 )
                self.assertEqual( t4[1] , 1 )
Exemplo n.º 2
0
    def test_load(self):
        with TestAreaContext("runpath_list"):
            with self.assertRaises(IOError):
                rp = RunpathList("")

            node0 = RunpathNode(0, 0, "path0", "base0")
            node1 = RunpathNode(1, 1, "path1", "base1")

            runpath_list = RunpathList("filex.list")
            with self.assertRaises(IOError):
                runpath_list.load()

            with open("invalid_file", "w") as f:
                f.write("X X X X\n")

            rp = RunpathList("invalid_file")
            with self.assertRaises(IOError):
                rp.load()

            rp = RunpathList("list.txt")
            rp.add(node0.realization, node0.iteration, node0.runpath,
                   node0.basename)
            rp.add(node1.realization, node1.iteration, node1.runpath,
                   node1.basename)
            rp.export()
            self.assertTrue(os.path.isfile("list.txt"))

            rp2 = RunpathList("list.txt")
            rp2.load()
            self.assertEqual(len(rp2), 2)
            self.assertEqual(rp2[0], node0)
            self.assertEqual(rp2[1], node1)