class TestTaskFolder(unittest.TestCase): """ Tests for the class TaskFolder .. moduleauthor:: Albert Heinle <*****@*****.**> """ def setUp(self): testName = "PrettyTestTask" testComputationProblem = "PrettierComputationProblem" testSDTables = ["sdtable1", "sdtable2"] testPIs = ["PI1", "PI2", "PI3", "PI4"] testCASs = ["Singular", "Magma", "Maple"] self.testTask = Task(testName, testComputationProblem, testSDTables, testPIs, testCASs) casDict = {"Singular": "Singular", "Magma": "magma", "Maple": "maple"} timeCommand = "time -p" self.msTest = MachineSettings(casDict, timeCommand) self.tfTree = TaskFolderTree() for a in testSDTables: for b in testPIs: for c in testCASs: self.tfTree.addCode(a, b, c, "/*Test Code*/") def testTaskFolder(self): """ Here, we test the functionality of the TaskFolder Class Tests include: 1. Initialization of the TaskFolder Class 1.a. A test, that initializes the taskFolder with None for all values. 1.b. A test, that the entries inside of the taskfoldertree coincide with the values that can be found in the task-instance, which is given to the function. 1.c Correct initialization of the TaskFolder instance. """ #1.a testVar = 0 try: tf = TaskFolder(None, None, None) testVar = 1 except: pass if (testVar == 1): self.fail( "I was able to initialize a TaskFolder instance with lots of None's as input" ) #1.b try: tf = TaskFolder(self.testTask, self.tfTree, TaskFolderTree()) testVar = 1 except: pass if testVar == 1: self.fail( "Could initialize the a Taskfolder with not consistent input.") #1.c try: tf = TaskFolder(self.testTask, self.tfTree, self.msTest) except: self.fail("Could not initialize correct Initialization of tfTree.")
class TestTaskFolder(unittest.TestCase): """ Tests for the class TaskFolder .. moduleauthor:: Albert Heinle <*****@*****.**> """ def setUp(self): testName = "PrettyTestTask" testComputationProblem = "PrettierComputationProblem" testSDTables = ["sdtable1", "sdtable2"] testPIs = ["PI1", "PI2", "PI3", "PI4"] testCASs = ["Singular", "Magma", "Maple"] self.testTask = Task(testName, testComputationProblem, testSDTables, testPIs, testCASs) casDict = {"Singular":"Singular", "Magma":"magma", "Maple":"maple"} timeCommand = "time -p" self.msTest = MachineSettings(casDict,timeCommand) self.tfTree = TaskFolderTree() for a in testSDTables: for b in testPIs: for c in testCASs: self.tfTree.addCode(a,b,c,"/*Test Code*/") def testTaskFolder(self): """ Here, we test the functionality of the TaskFolder Class Tests include: 1. Initialization of the TaskFolder Class 1.a. A test, that initializes the taskFolder with None for all values. 1.b. A test, that the entries inside of the taskfoldertree coincide with the values that can be found in the task-instance, which is given to the function. 1.c Correct initialization of the TaskFolder instance. """ #1.a testVar =0 try: tf = TaskFolder(None,None,None) testVar = 1 except: pass if (testVar==1): self.fail("I was able to initialize a TaskFolder instance with lots of None's as input") #1.b try: tf = TaskFolder(self.testTask, self.tfTree, TaskFolderTree()) testVar =1 except: pass if testVar == 1: self.fail("Could initialize the a Taskfolder with not consistent input.") #1.c try: tf = TaskFolder(self.testTask, self.tfTree, self.msTest) except: self.fail("Could not initialize correct Initialization of tfTree.")
def testTaskFolder(self): """ Here, we test the functionality of the TaskFolder Class Tests include: 1. Initialization of the TaskFolder Class 1.a. A test, that initializes the taskFolder with None for all values. 1.b. A test, that the entries inside of the taskfoldertree coincide with the values that can be found in the task-instance, which is given to the function. 1.c Correct initialization of the TaskFolder instance. """ #1.a testVar = 0 try: tf = TaskFolder(None, None, None) testVar = 1 except: pass if (testVar == 1): self.fail( "I was able to initialize a TaskFolder instance with lots of None's as input" ) #1.b try: tf = TaskFolder(self.testTask, self.tfTree, TaskFolderTree()) testVar = 1 except: pass if testVar == 1: self.fail( "Could initialize the a Taskfolder with not consistent input.") #1.c try: tf = TaskFolder(self.testTask, self.tfTree, self.msTest) except: self.fail("Could not initialize correct Initialization of tfTree.")
def setUp(self): testName = "PrettyTestTask" testComputationProblem = "PrettierComputationProblem" testSDTables = ["sdtable1", "sdtable2"] testPIs = ["PI1", "PI2", "PI3", "PI4"] testCASs = ["Singular", "Magma", "Maple"] self.testTask = Task(testName, testComputationProblem, testSDTables, testPIs, testCASs) casDict = {"Singular": "Singular", "Magma": "magma", "Maple": "maple"} timeCommand = "time -p" self.msTest = MachineSettings(casDict, timeCommand) self.tfTree = TaskFolderTree() for a in testSDTables: for b in testPIs: for c in testCASs: self.tfTree.addCode(a, b, c, "/*Test Code*/")
def create(self, task, xmlRessources, machineSettings): """ The function that creates the taskfolder using the information given in task, the xmlRessources, and the machineSettings. :param task: The task associated to the taskfolder :type task: Task :param xmlRessources: The interface to the XMLRessources folder in Symbolic Data :type xmlRessources: XMLRessources :param machineSettings: The machine settings of the target machine :type machineSettings: MachineSettings :raises NotImplementedError: If there is a template not existing. :returns: An instance of taskfolder fitting to the given task. :rtype: TaskFolder """ pathOfSDEval = os.path.split( os.path.realpath(os.path.dirname(__file__)))[0] #The only thing we need to create is The taskfolderTree tft = TaskFolderTree() for s in task.getAssociatedSDTables(): sdt = xmlRessources.loadSDTable(s) for p in filter(lambda x: x in sdt.listEntries(), task.getProblemInstances()): for c in task.getComputerAlgebraSystems(): #-------------------- complicated python stuff -------------------- # What happens here in the next lines: # We load dynamically the builder for the problem instance given by p. Then we create the instance with the # information we know. Those builder and problem instances are found in the module "probleminstances". # After that, we search for the computation problem template for the computer algebra system c. # We will use that function to generate code later for our TaskFolderTree. fromXMLBuilderModule = __import__( "probleminstances.%sFromXMLBuilder" % sdt.getName(), globals(), locals(), ["%sFromXMLBuilder" % sdt.getName()]) builderfunc = getattr(fromXMLBuilderModule, "%sFromXMLBuilder" % sdt.getName()) creator = builderfunc(sdt) pi = creator.build(p) codegeneratingModule = __import__( "templates.comp.%s.%s.template" % (task.getComputationProblem(), c), globals(), locals(), ["generateCode"]) codeGenerator = codegeneratingModule.generateCode #-------------------- end of complicated python stuff ------------- if task.getComputationProblem() == "GB_Z_lp": tft.addCode(sdt.getName(), p, c, codeGenerator(pi.getVars(), pi.getBasis())) elif task.getComputationProblem() == "GB_Fp_dp": tft.addCode( sdt.getName(), p, c, codeGenerator(pi.getVars(), pi.getBasis(), pi.getCharacteristic())) elif task.getComputationProblem() == "FA_Q_dp": tft.addCode( sdt.getName(), p, c, codeGenerator(pi.getVars(), pi.getBasis(), pi.getUpToDeg())) return TaskFolder(task, tft, machineSettings)
def create(self,task, xmlRessources, machineSettings): """ The function that creates the taskfolder using the information given in task, the xmlRessources, and the machineSettings. If the input is not valid, None is returned. :param task: The task associated to the taskfolder :type task: Task :param xmlRessources: The interface to the XMLResources folder in Symbolic Data :type xmlRessources: XMLResources :param machineSettings: The machine settings of the target machine :type machineSettings: MachineSettings :raises ImportError: If there is a template not existing. :returns: An instance of taskfolder fitting to the given task. :rtype: TaskFolder or None """ if (task == None or xmlRessources == None or machineSettings == None): return None if ((not isinstance(task, Task)) or (not isinstance(xmlRessources,XMLResources)) or (not isinstance(machineSettings,MachineSettings))): return None #Done input check pathOfSDEval = os.path.split(os.path.realpath(os.path.dirname(__file__)))[0] #The only thing we need to create is The taskfolderTree tft = TaskFolderTree() for s in task.getAssociatedSDTables(): sdt = xmlRessources.loadSDTable(s) for p in filter(lambda x: x in sdt.listEntries(),task.getProblemInstances()): for c in task.getComputerAlgebraSystems(): #-------------------- complicated python stuff -------------------- # What happens here in the next lines: # We load dynamically the builder for the problem instance given by p. Then we create the instance with the # information we know. Those builder and problem instances are found in the module "probleminstances". # After that, we search for the computation problem template for the computer algebra system c. # We will use that function to generate code later for our TaskFolderTree. fromXMLBuilderModule = __import__("probleminstances.%sFromXMLBuilder"%sdt.getName(),globals(),locals(),["%sFromXMLBuilder"%sdt.getName()]) builderfunc = getattr(fromXMLBuilderModule,"%sFromXMLBuilder"%sdt.getName()) creator = builderfunc(sdt) pi = creator.build(p) codegeneratingModule = __import__("templates.comp.%s.%s.template"%(task.getComputationProblem(),c),globals(),locals(),["generateCode"]) codeGenerator = codegeneratingModule.generateCode #-------------------- end of complicated python stuff ------------- if task.getComputationProblem() == "GB_Z_lp": tft.addCode(sdt.getName(),p,c,codeGenerator(pi.getVars(),pi.getBasis())) elif task.getComputationProblem() == "GB_Fp_dp": tft.addCode(sdt.getName(),p,c,codeGenerator(pi.getVars(),pi.getBasis(),pi.getCharacteristic())) elif task.getComputationProblem() == "FA_Q_dp": tft.addCode(sdt.getName(),p,c,codeGenerator(pi.getVars(),pi.getBasis(),pi.getUpToDeg())) elif task.getComputationProblem() == "SOL_R_poly_sys": tft.addCode(sdt.getName(),p,c,codeGenerator(pi.getVars(),pi.getBasis())) return TaskFolder(task,tft,machineSettings)
def setUp(self): testName = "PrettyTestTask" testComputationProblem = "PrettierComputationProblem" testSDTables = ["sdtable1", "sdtable2"] testPIs = ["PI1", "PI2", "PI3", "PI4"] testCASs = ["Singular", "Magma", "Maple"] self.testTask = Task(testName, testComputationProblem, testSDTables, testPIs, testCASs) casDict = {"Singular":"Singular", "Magma":"magma", "Maple":"maple"} timeCommand = "time -p" self.msTest = MachineSettings(casDict,timeCommand) self.tfTree = TaskFolderTree() for a in testSDTables: for b in testPIs: for c in testCASs: self.tfTree.addCode(a,b,c,"/*Test Code*/")
def test_TaskFolderTree(self): """ Testing the main functionality of TaskFolderTree This function includes the following tests: 1. Test correct initialization (i.e. all paths should be empty) 2. Test string representation 1. empty tree 2. filled tree 3. Add paths and check all the getters to be correct or not. """ #1. tft = TaskFolderTree() self.assertEqual(tft.getAllPaths(),[],"Initial paths list in TaskFolderTree is not empty") self.assertEqual(tft.getPathsBySDTable("asdklfh"),[],"Initial paths list contains an entry with SDTable") self.assertEqual(tft.getPathsByProblemInstance("ireotueroi"),[], "Initial paths list contains an entry with a probleminstance") self.assertEqual(tft.getPathsByComputerAlgebraSystem("'ukl;yu;klp"),[], "Initial paths list contains an entry with a cas") #2.1 self.assertEqual(str(tft), "Empty Tree", "String representation of empty tree was not valid.") #2.2 tft.addCode("MySDTable", "MyPI1", "MyCAS1", "maleficient code 1.") tft.addCode("MySDTable", "MyPI2", "MyCAS1", "maleficient code 2.") tft.addCode("MySDTable", "MyPI1", "MyCAS2", "maleficient code 3.") tft.addCode("MySDTable", "MyPI2", "MyCAS2", "maleficient code 4.") expectedStringRep = """MySDTable: MyPI1: MyCAS1 MyCAS2 MyPI2: MyCAS1 MyCAS2 """ self.assertEqual(str(tft),expectedStringRep, "String representation of non-empty Tree is not valid") #3 self.assertEqual(len(tft.getAllPaths()),4,"Amount of Paths was wrong") self.assertEqual(len(tft.getPathsBySDTable("MySDTable")),4,"Path number by SDTable was wrong") self.assertEqual(len(tft.getPathsByProblemInstance("MyPI1")),2,"Path number by Problem instance was wrong") self.assertEqual(len(tft.getPathsByComputerAlgebraSystem("MyCAS1")),2, "Path number by CAS was wrong")
def test_TaskFolderTree(self): """ Testing the main functionality of TaskFolderTree This function includes the following tests: 1. Test correct initialization (i.e. all paths should be empty) 2. Test string representation 1. empty tree 2. filled tree 3. Add paths and check all the getters to be correct or not. """ #1. tft = TaskFolderTree() self.assertEqual(tft.getAllPaths(), [], "Initial paths list in TaskFolderTree is not empty") self.assertEqual(tft.getPathsBySDTable("asdklfh"), [], "Initial paths list contains an entry with SDTable") self.assertEqual( tft.getPathsByProblemInstance("ireotueroi"), [], "Initial paths list contains an entry with a probleminstance") self.assertEqual(tft.getPathsByComputerAlgebraSystem("'ukl;yu;klp"), [], "Initial paths list contains an entry with a cas") #2.1 self.assertEqual(str(tft), "Empty Tree", "String representation of empty tree was not valid.") #2.2 tft.addCode("MySDTable", "MyPI1", "MyCAS1", "maleficient code 1.") tft.addCode("MySDTable", "MyPI2", "MyCAS1", "maleficient code 2.") tft.addCode("MySDTable", "MyPI1", "MyCAS2", "maleficient code 3.") tft.addCode("MySDTable", "MyPI2", "MyCAS2", "maleficient code 4.") expectedStringRep = """MySDTable: MyPI1: MyCAS1 MyCAS2 MyPI2: MyCAS1 MyCAS2 """ self.assertEqual( str(tft), expectedStringRep, "String representation of non-empty Tree is not valid") #3 self.assertEqual(len(tft.getAllPaths()), 4, "Amount of Paths was wrong") self.assertEqual(len(tft.getPathsBySDTable("MySDTable")), 4, "Path number by SDTable was wrong") self.assertEqual(len(tft.getPathsByProblemInstance("MyPI1")), 2, "Path number by Problem instance was wrong") self.assertEqual(len(tft.getPathsByComputerAlgebraSystem("MyCAS1")), 2, "Path number by CAS was wrong")