Esempio n. 1
0
 def onNewActionPipeline():
     ap = ActionPipeline()
     blackBoxEditor = BlackBoxEditorDialog(ap)
     result = blackBoxEditor.exec_()
     if result == QDialog.Rejected:
         return
     else:
         self._project.getAPIModel().addActionPipeline(ap)
         v._actionPipelinesMenu.addAction(ap)
         ui.actionMenuTabWidget.setCurrentWidget(v._actionPipelinesMenu)
Esempio n. 2
0
	def test_ActionPipeline(self):
		
		# create top-level action pipeline
		readAccountBalance = ActionPipeline()
		self.assertTrue(readAccountBalance.getActions() == [])
		self.assertTrue(readAccountBalance.getInputPorts() == [])
		self.assertTrue(readAccountBalance.getOutputPorts() == [])
		
		# create ports and add them to the top-level action pipeline
		username = Port()
		username.setOptional(False)
		username.setDataType(str)
		self.assertFalse(username.isOptional())
		self.assertTrue(username.getDataType() == str)
		pwd = Port()
		pwd.setOptional(False)
		pwd.setDataType(str)
		self.assertFalse(pwd.isOptional())
		self.assertTrue(pwd.getDataType() == str)
		accountBalance = Port()
		readAccountBalance.addInputPort(username)
		readAccountBalance.addInputPort(pwd)
		readAccountBalance.addOutputPort(accountBalance)
		self.assertTrue(readAccountBalance.getActions() == [])
		self.assertTrue(readAccountBalance.getInputPorts() == [username, pwd])
		self.assertTrue(readAccountBalance.getOutputPorts() == [accountBalance])
		
		# create another action pipeline that won't be a child of the top-level
		temp = ActionPipeline()
		tempPort = Port()
		temp.addInputPort(tempPort)
		
		# Create a sub-action pipeline with ports
		login = ActionPipeline()
		uname = Port()
		password = Port()
		login.addInputPort(uname)
		login.addInputPort(password)
		self.assertTrue(login.getActions() == [])
		self.assertTrue(login.getInputPorts() == [uname, password])
		self.assertTrue(login.getOutputPorts() == [])
		
		# Create a wrapper for the sub-action pipeline
		loginWrapper = ActionWrapper(login, readAccountBalance)
		w_uname, w_password = loginWrapper.getInputPorts()
		
		self.assertTrue(type(w_uname) == Port)
		self.assertTrue(type(w_password) == Port)
		self.assertTrue(w_uname.isOptional() == uname.isOptional())
		self.assertTrue(w_uname.getDataType() == uname.getDataType())
		self.assertTrue(w_password.isOptional() == password.isOptional())
		self.assertTrue(w_password.getDataType() == password.getDataType())
		
		uname = w_uname
		password = w_password
		
		# Add sub-action pipeline to top-level action pipeline.
		#readAccountBalance.addAction(loginWrapper)
		self.assertTrue(readAccountBalance.getActions() == [loginWrapper])
		
		# Make sure we can't add a non-wrapper action to an action pipeline
		self.assertRaises(ActionException, lambda: readAccountBalance.addAction(login))
		
		# make sure we can't add the uname port again
		self.assertRaises(PortException, lambda: login.addInputPort(uname))
		self.assertRaises(PortException, lambda: login.addOutputPort(uname))
		self.assertRaises(PortException, lambda: readAccountBalance.addInputPort(uname))
		self.assertRaises(PortException, lambda: readAccountBalance.addOutputPort(uname))
		self.assertRaises(PortException, lambda: ActionPipeline().addInputPort(uname))
		self.assertRaises(PortException, lambda: ActionPipeline().addOutputPort(uname))
		
		# connect wires
		readAccountBalance.connect(username, uname)
		readAccountBalance.connect(pwd, password)
		
		# make sure wires exist
		self.assertTrue(readAccountBalance.getWireSet().containsWire(username, uname))
		self.assertTrue(readAccountBalance.getWireSet().containsWire(pwd, password))
		
		# make sure that you can't connect the wires again.
		self.assertRaises(PortException, lambda: readAccountBalance.connect(username, uname))
		self.assertRaises(PortException, lambda: readAccountBalance.connect(pwd, uname))
		
		# disconnect the username wire
		readAccountBalance.disconnect(username, uname)
		self.assertRaises(WireException, lambda: readAccountBalance.disconnect(username, uname))
		
		# remove the ports from the top-level action, add them to the sub-action, then move them
		# back.
		readAccountBalance.removePort(username)
		readAccountBalance.removePort(accountBalance)
		self.assertTrue(readAccountBalance.getInputPorts() == [pwd])
		self.assertTrue(readAccountBalance.getOutputPorts() == [])
		self.assertTrue(username.getAction() is None)
		self.assertTrue(accountBalance.getAction() is None)
		self.assertRaises(PortException, lambda: readAccountBalance.removePort(username))
		self.assertRaises(PortException, lambda: readAccountBalance.removePort(accountBalance))
		self.assertRaises(PortException, lambda: readAccountBalance.removePort(Port()))
		self.assertRaises(PortException, lambda: readAccountBalance.removePort(tempPort))
		self.assertFalse(readAccountBalance.getWireSet().containsWire(username, uname))
		login.addInputPort(username)
		login.addOutputPort(accountBalance)
		login.removePort(username)
		login.removePort(accountBalance)
		readAccountBalance.addInputPort(username)
		readAccountBalance.addOutputPort(accountBalance)
		readAccountBalance.connect(username, uname)
		self.assertTrue(readAccountBalance.getWireSet().containsWire(username, uname))
		self.assertTrue(readAccountBalance.getWireSet().containsWire(pwd, password))
		
		# change sequence of actions
		readAccountBalance.changeSequence([loginWrapper])
		self.assertRaises(ActionException, lambda: readAccountBalance.changeSequence([loginWrapper,ActionPipeline]))
		self.assertRaises(ActionException, lambda: readAccountBalance.changeSequence([loginWrapper,loginWrapper]))
		self.assertRaises(ActionException, lambda: readAccountBalance.changeSequence([]))
		
		# Make sure we can't connect/disconnect ports that we don't have access to.
		self.assertRaises(PortException, lambda: readAccountBalance.connect(username, Port()))
		self.assertRaises(PortException, lambda: readAccountBalance.connect(Port(), username))
		self.assertRaises(PortException, lambda: readAccountBalance.disconnect(username, Port()))
		self.assertRaises(PortException, lambda: readAccountBalance.disconnect(Port(), username))
		
		# make sure we can't connect the username ports backwards
		self.assertRaises(WireException, lambda: readAccountBalance.connect(uname, username))
	
		# action deletion
		self.assertRaises(ActionException, lambda: readAccountBalance.removeAction(login))
		readAccountBalance.removeAction(loginWrapper)
		self.assertFalse(readAccountBalance.getWireSet().containsWire(username, uname))
		self.assertFalse(readAccountBalance.getWireSet().containsWire(pwd, password))
		
		# Add a component action to read from the account balance field

		# TODO: Update ComponentAction constructor call
		#readField = ComponentAction(None, "This is a bullshit component action")
		readField = ActionPipeline()
		balanceStr = Port()
		readField.addOutputPort(balanceStr)
		
		readFieldWrapper = ActionWrapper(readField, readAccountBalance)
		balanceStr2, = readFieldWrapper.getOutputPorts()
		
		#readAccountBalance.addAction(readFieldWrapper)
		readAccountBalance.connect(balanceStr2, accountBalance)
		self.assertRaises(PortException, lambda: readAccountBalance.connect(balanceStr, accountBalance))
Esempio n. 3
0
	def test_ActionWrapper(self):
		# make an action pipeline
		ap = ActionPipeline()
		p1 = Port()
		p2 = Port()
		ap.addInputPort(p1)
		ap.addOutputPort(p2)
		
		# make a wrapper for it
		parent = ActionPipeline()
		w = ActionWrapper(ap, parent)
		p1Mirror, = w.getInputPorts()
		p2Mirror, = w.getOutputPorts()
		
		self.assertTrue(p1Mirror is not p1)
		self.assertTrue(p2Mirror is not p2)
		self.assertTrue(type(p1Mirror) == Port)
		self.assertTrue(type(p2Mirror) == Port)
		self.assertTrue(p1Mirror.isOptional() == p1.isOptional())
		self.assertTrue(p1Mirror.getDataType() == p1.getDataType())
		self.assertTrue(p2Mirror.isOptional() == p2.isOptional())
		self.assertTrue(p2Mirror.getDataType() == p2.getDataType())
		
		# Add another port to the action pipeline and make sure the wrapper is updated
		ap.addInputPort(Port())
		self.assertTrue(len(ap.getInputPorts()) == len(w.getInputPorts()))
		
		ap.removePort(p1)
		self.assertTrue(len(ap.getInputPorts()) == len(w.getInputPorts()))
		
		ap.removePort(p2)
		self.assertTrue(len(ap.getInputPorts()) == len(w.getInputPorts()))
		
		self.assertRaises(ActionException, lambda: ActionPipeline().registerWrapper(w))
		self.assertRaises(ActionException, lambda: ActionPipeline().unRegisterWrapper(w))
		self.assertRaises(ActionException, lambda: ap.unRegisterWrapper(w))
		
		w.forgetActionReference()
		ap.unRegisterWrapper(w)
		
		self.assertRaises(ActionException, lambda: ActionPipeline().addAction(w))
		self.assertRaises(ActionException, lambda: parent.addAction(w))
		
Esempio n. 4
0
		:param text: Text that will be in the label.
		:type text: str
		:return: None
		:rtype: Nonetype
		"""
        self.ui.menuLabel.setText(text)


if __name__ == "__main__":
    app = QApplication()
    w = ActionMenu()
    p1 = Port()
    p2 = Port()
    p3 = Port()
    p4 = Port()
    p5 = Port()
    ap = ActionPipeline()
    ap.addInputPort(p1)
    ap.addInputPort(p2)
    ap.addOutputPort(p3)
    ap.addOutputPort(p4)
    ap.addOutputPort(p5)

    for i in range(10):
        ap.getProperties().getProperty("Name")[1].setValue("Action Pipeline" +
                                                           str(i))
        w.addAction(ap)

    w.show()

    sys.exit(app.exec_())
	def test_ActionMethodDocStrings(self):
		ap = ActionPipeline()
		ap.setName("myAction")
		
		# set the input ports
		p1 = pt.Port()
		p1.setDataType(int)
		p1.setName("input1")
		p1.setOptional(False)
		ap.addInputPort(p1)
		p2 = pt.Port()
		p2.setDataType(bool)
		p2.setName("input2")
		p2.setOptional(False)
		ap.addInputPort(p2)
		
		# set the output ports
		p3 = pt.Port()
		p3.setDataType(str)
		p3.setName("output1")
		ap.addOutputPort(p3)
		
		doc = '''"""
		Add a comment here...

		:param input1: Add a comment here...
		:type input1: int
		:param input2: Add a comment here...
		:type input2: bool
		:return: (Add a comment here...)
		:rtype: (str)
		"""'''
		self.assertTrue(ap.getDocStr().strip() == doc)
		
		ap.setAnnotation("This is my action pipeline. Only mine.")
		doc = '''"""
		This is my action pipeline. Only mine.

		:param input1: Add a comment here...
		:type input1: int
		:param input2: Add a comment here...
		:type input2: bool
		:return: (Add a comment here...)
		:rtype: (str)
		"""'''
		self.assertTrue(ap.getDocStr().strip() == doc)
		
		ap.setName("login")
		ap.setAnnotation("Login to the Chase Desktop banking app.")
		p1.setName("username")
		p1.setDataType(str)
		p1.setOptional(False)
		p1.setAnnotation("Your username (case-sensitive)")
		p2.setName("Password")
		p2.setDataType(str)
		p2.setOptional(False)
		p2.setAnnotation("Your password (case-sensitive)")
		p3.setName("Success")
		p3.setDataType(bool)
		p3.setOptional(False)
		p3.setAnnotation("A flag saying whether the login attempt was successful or not.")
		
		doc = '''"""
		Login to the Chase Desktop banking app.

		:param username: Your username (case-sensitive)
		:type username: str
		:param Password: Your password (case-sensitive)
		:type Password: str
		:return: (A flag saying whether the login attempt was successful or not.)
		:rtype: (bool)
		"""'''
		self.assertTrue(ap.getDocStr().strip() == doc)
		
		p4 = pt.Port()
		p4.setName("numLoginAttempts")
		p4.setDataType(int)
		p4.setAnnotation("The number of login attempts it took to succeed (-1 if no success).")
		p4.setOptional(False)
		ap.addOutputPort(p4)
		doc = '''"""
		Login to the Chase Desktop banking app.

		:param username: Your username (case-sensitive)
		:type username: str
		:param Password: Your password (case-sensitive)
		:type Password: str
		:return: (A flag saying whether the login attempt was successful or not., The number of login attempts it took to succeed (-1 if no success).)
		:rtype: (bool, int)
		"""'''

		self.assertTrue(ap.getDocStr().strip() == doc)
	def test_ActionMethodSignatures(self):
		"""
		This function makes sure that the method signatures are generated
		correctly for any action with an arbitrary number of ports.
		"""
		ap = ActionPipeline()
		ap.setName("myAction")
		
		# set the input ports
		p1 = pt.Port()
		p1.setDataType(int)
		p1.setName("input1")
		p1.setOptional(False)
		ap.addInputPort(p1)
		p2 = pt.Port()
		p2.setDataType(bool)
		p2.setName("input2")
		p2.setOptional(False)
		ap.addInputPort(p2)
		
		# set the output ports
		p3 = pt.Port()
		p3.setDataType(str)
		p3.setName("output1")
		ap.addOutputPort(p3)
		
		sig = "\tdef myAction(self, input1: int, input2: bool) -> str:\n"
		self.assertTrue(ap.getMethodSignature() == sig)
		
		# TODO: Still need to handle optional parameters.
		p2.setOptional(True)
		self.assertFalse(ap.getMethodSignature() == sig)
	def test_ActionPipelineCodeGeneration(self):
		"""
		This function makes sure that the code is generated
		correctly for any action pipeline.
		"""
		app = QApplication([])

		proj = Project('test', 'test project', '', 'uia')
		tguim = proj.getTargetGUIModel()

		ap = ActionPipeline()  # should have id 0
		ap2 = ActionPipeline()  # should have id 1

		ap.setName('custom1')
		ap.setAnnotation('testing the first pipeline')

		p = pt.Port()
		p.setName("value")
		p.setDataType(str)
		p.setAnnotation("Value to be written.")
		p.setOptional(False)
		ap.addInputPort(p)

		ap2.setName('custom2')
		ap2.setAnnotation('testing the second pipeline')

		p1 = pt.Port()
		p1.setName("value")
		p1.setDataType(str)
		p1.setAnnotation("Value to be written.")
		p1.setOptional(False)
		ap2.addInputPort(p1)

		comp1 = Component(tguim)  # should have id 2
		comp2 = Component(tguim)  # should have id 3
		comp3 = Component(tguim)  # should have id 4
		comp4 = Component(tguim)  # should have id 5

		spec1 = ActionSpecification.fromFile('../../../database/component_actions/click.action')
		spec2 = ActionSpecification.fromFile('../../../database/component_actions/write.action')
		spec3 = ActionSpecification.fromFile('../../../database/component_actions/read.action')

		a1 = ComponentAction(comp1, spec1) #6 and so on
		a2 = ComponentAction(comp2, spec1)
		a3 = ComponentAction(comp3, spec2)
		a4 = ComponentAction(comp4, spec3)

		aw1 = ActionWrapper(a1, ap)
		aw2 = ActionWrapper(a2, ap)
		aw3 = ActionWrapper(a3, ap)
		aw5 = ActionWrapper(ap, ap2)
		aw4 = ActionWrapper(a4, ap2)

		ap.connect(p, aw3.getInputPorts()[0])
		ap2.connect(p1, aw5.getInputPorts()[0])

		method1 = '''\
	def custom1(self, value: str) -> None:
		"""
		testing the first pipeline

		:param value: Value to be written.
		:type value: str
		:return: None
		:rtype: NoneType
		"""

		self._6_click()
		self._7_click()
		self._8_write(value)

'''

		method2 = '''\
	def custom2(self, value: str) -> None:
		"""
		testing the second pipeline

		:param value: Value to be written.
		:type value: str
		:return: None
		:rtype: NoneType
		"""

		self.custom1(value)
		a = self._9_read()

'''

		print([li for li in difflib.ndiff(ap.getMethod(), method1) if li[0] != ' '])
		print(ap.getMethod())
		print([li for li in difflib.ndiff(ap2.getMethod(), method2) if li[0] != ' '])
		print(ap2.getMethod())

		self.assertTrue(ap.getMethod() == method1)
		self.assertTrue(ap2.getMethod() == method2)
Esempio n. 8
0
		:param event: the event carrying the location of the right-click
		:return: None
		"""
        self.menu.prerequest()
        self.menu.exec_(event.screenPos())


if __name__ == "__main__":
    app = QApplication()
    v = QGraphicsView()
    v.setGeometry(500, 500, 500, 500)
    s = QGraphicsScene()
    v.setScene(s)

    # Create top-level actionPipeline.
    actPipeline = ActionPipeline()

    # Add some ports to it.
    inPort1 = Port()
    inPort2 = Port()
    outPort1 = Port()
    actPipeline.addInputPort(inPort1)
    actPipeline.addInputPort(inPort2)
    actPipeline.addOutputPort(outPort1)

    #Sub-Actions
    act1 = ActionPipeline()
    act1.setName("action pipeline 1")
    act2 = ActionPipeline()
    act2.setName("action pipeline 2")