예제 #1
0
class TestDefaultTextValidator(TestCase):
    def setUp(self) -> None:
        self.min_length = 16
        self.max_length = 256
        self.validator = TextValidator()

    def test_valid(self):
        num_chars = randint(self.min_length, self.max_length)
        valid_text = gen_random_text(num_chars)
        self.assertTrue(self.validator.is_valid(valid_text))

    def test_invalid_min(self):
        num_chars = randint(-999, 15)
        valid_text = gen_random_text(num_chars)
        self.assertFalse(self.validator.is_valid(valid_text))

    def test_invalid_max(self):
        num_chars = randint(257, 999)
        valid_text = gen_random_text(num_chars)
        self.assertFalse(self.validator.is_valid(valid_text))

    def test_absolute_min_valid(self):
        valid_text = gen_random_text(self.min_length)
        self.assertTrue(self.validator.is_valid(valid_text))

    def test_absolute_max_valid(self):
        valid_text = gen_random_text(self.max_length)
        self.assertTrue(self.validator.is_valid(valid_text))
예제 #2
0
 def _create_additional_controls(self):
     """
     Create custom controls
     """
     self.add_to_layout(
         wx.TextCtrl(self,
                     validator=TextValidator(self, "verif"),
                     size=(150, 26)), "Regular expression")
     self.add_to_layout(
         wx.TextCtrl(self,
                     validator=TextValidator(self, "default"),
                     size=(150, 26)), "Default value")
예제 #3
0
 def _createControls(self):
     """
     Create GUI controls
     """
     # Add controls to the layout
     self.addToLayout(
         wx.TextCtrl(self,
                     validator=TextValidator(self, "portname"),
                     size=(200, 26)), "Serial port")
     self.addToLayout(
         wx.TextCtrl(self, validator=TextValidator(self, "portspeed")),
         "Serial baud rate (bps)")
     self.addOkCancelButtons()
예제 #4
0
파일: fields.py 프로젝트: anikinator/phyton
 def __init__(self, validators=None):
     self.default_validators = [
         TextValidator(min_length=1001, max_length=3000)
     ]
     self.all_validators = self.default_validators
     if isinstance(validators, list) and validators:
         self.all_validators = self.default_validators + validators
예제 #5
0
    def _createControls(self):
        """
        Create GUI controls
        """
        # Add controls to the layout       
        self.addToLayout(wx.CheckBox(self, -1, "Anti-playback", validator=BoolValidator(self, "playbk")))
        self.addToLayout(wx.CheckBox(self, -1, "Smart encryption", validator=BoolValidator(self, "smartencrypt")))

        self.addToLayout(wx.TextCtrl(self, validator=TextValidator(self, "password", regex="^[A-Fa-f0-9-]{24}$"), size=(150, 26)), "Password (12 bytes, hex)")
        self.addOkCancelButtons()
예제 #6
0
    def create_controls(self):
        """
        Create GUI controls
        """
        # Add controls to the layout
        self.add_to_layout(
            wx.TextCtrl(self,
                        validator=TextValidator(self,
                                                "paramname",
                                                regex="^[a-zA-Z0-9_-]+$"),
                        size=(150, 26)), "Name (blank spaces not allowed)")

        self.rb_type_num = wx.RadioButton(self,
                                          -1,
                                          'Numeric value', (10, 10),
                                          style=wx.RB_GROUP)
        self.rb_type_bin = wx.RadioButton(self, -1, 'Binary value', (10, 30))
        self.rb_type_str = wx.RadioButton(self, -1, 'String value', (10, 50))
        self.Bind(wx.EVT_RADIOBUTTON,
                  self.set_type,
                  id=self.rb_type_num.GetId())
        self.Bind(wx.EVT_RADIOBUTTON,
                  self.set_type,
                  id=self.rb_type_bin.GetId())
        self.Bind(wx.EVT_RADIOBUTTON,
                  self.set_type,
                  id=self.rb_type_str.GetId())

        self.add_to_layout(self.rb_type_num, "Data type:")
        self.add_to_layout(self.rb_type_bin)
        self.add_to_layout(self.rb_type_str)

        self.add_to_layout(
            wx.TextCtrl(
                self,
                validator=TextValidator(
                    self,
                    "bitsize",
                    regex=
                    "^([1-9]|[1-9][0-9]|[1-3][0-9][0-9]|[4][0-3][0-9]|[440])$"
                ),
                size=(70, 26)), "Size in bits")
예제 #7
0
 def _createControls(self):
     """
     Create GUI controls
     """
     # Add controls to the layout
     self.addToLayout(
         wx.TextCtrl(self, validator=TextValidator(self, "freq_channel")),
         "Frequency channel")
     self.addToLayout(
         wx.TextCtrl(self,
                     validator=TextValidator(self,
                                             "netid",
                                             regex="^[A-Fa-f0-9-]{4}$")),
         "Network ID")
     self.addToLayout(
         wx.TextCtrl(self, validator=TextValidator(self, "devaddress")),
         "Device address")
     self.addToLayout(
         wx.TextCtrl(self, validator=TextValidator(self, "interval")),
         "Periodic Tx interval")
     self.addOkCancelButtons()
예제 #8
0
    def _addWidget(self, index):
        """
        Add widget to the layout
        
        'index'    Index of hte parameter within self.parameters
        """
        param = self.parameters[index]
        if param.type == SwapType.BINARY:
            self.addToLayout(wx.CheckBox(self, -1, param.name, validator=BoolValidator(self, "parameters", index)))
        elif param.type in [SwapType.NUMBER, SwapType.STRING]:
            addTextCtrl = False
            choices = []
            if param.verif is not None:
                if param.verif == "MONTH":
                    choices = ["January", "February", "March", "April", "June", "May", "July", "August", "September", "October", "November", "December"]
                elif param.verif == "YEAR":
                    for i in range(2011, 2060):
                        choices.append(str(i))
                elif param.verif == "MDAY":
                    for i in range(1, 32):
                        choices.append(str(i))
                elif param.verif == "WDAY":
                    choices = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
                elif param.verif in ["MINUTE", "SECOND"]:
                    for i in range(0, 10):
                        choices.append("0" + str(i))
                    for i in range(10, 60):
                        choices.append(str(i))
                elif param.verif == "HOUR":
                    for i in range(0, 10):
                        choices.append("0" + str(i))
                    for i in range(10, 24):
                        choices.append(str(i))
                elif len(param.verif) > 6:
                    if param.verif[:6] == "RANGE(":
                        comma = param.verif.find(",")
                        if comma > -1:
                            startRange = int(param.verif[6:comma])
                            endRange = int(param.verif[comma+1:-1])
                        else:
                            startRange = 0
                            endRange = int(param.verif[6:-1]) + 1
                        for i in range(startRange, endRange):
                            choices.append(str(i))
                    else:
                        addTextCtrl = True
                else:
                    addTextCtrl = True

            if addTextCtrl:
                self.addToLayout(wx.TextCtrl(self, -1, validator=TextValidator(self, "parameters", index, param.verif)), param.name)
            else:
                self.addToLayout(wx.ComboBox(self, validator=ListValidator(self, "parameters", index), choices=choices, style=wx.CB_READONLY), param.name)
예제 #9
0
 def create_controls(self):
     """
     Create GUI controls
     """
     # Add controls to the layout
     self.add_to_layout(
         wx.TextCtrl(self,
                     validator=TextValidator(self, "unit"),
                     size=(70, 26)), "Unit label")
     self.add_to_layout(
         wx.TextCtrl(self,
                     validator=TextValidator(self,
                                             "factor",
                                             regex="[-+]?[0-9]*\.?[0-9]+"),
                     size=(70, 26)), "Factor modifier")
     self.add_to_layout(
         wx.TextCtrl(self,
                     validator=TextValidator(self,
                                             "offset",
                                             regex="[-+]?[0-9]*\.?[0-9]+"),
                     size=(70, 26)), "Offset modifier")
     self.add_to_layout(
         wx.StaticText(self, label="Final value = value x factor + offset"))
     self.add_okcancel_buttons()
예제 #10
0
    def _create_controls(self):
        """
        Create GUI controls
        """
        # Add controls to the layout
        self.add_to_layout(
            wx.TextCtrl(self,
                        validator=TextValidator(self, "regname", regex="\S"),
                        size=(150, 26)), "Register name")
        self.add_to_layout(
            wx.TextCtrl(
                self,
                validator=TextValidator(
                    self,
                    "regid",
                    regex=
                    "^([1][1-9]|[2-9][0-9]|[1][0-9][0-9]|[2][0-1][0-9]|[22][0-5])$"
                ),
                size=(70, 26)), "Register ID (10-255)")

        # Create list box
        self.list_parameters = wx.ListCtrl(self,
                                           -1,
                                           style=wx.LC_REPORT,
                                           size=(275, 150))
        self.list_parameters.InsertColumn(0, "Parameter name")
        self.list_parameters.InsertColumn(1, "type")
        self.list_parameters.InsertColumn(2, "dir")
        self.list_parameters.SetColumnWidth(0, 140)
        self.list_parameters.SetColumnWidth(1, 50)
        self.list_parameters.SetColumnWidth(1, 50)

        self.add_to_layout(self.list_parameters, "List of parameters")

        self.add_list_buttons()
        self.add_okcancel_buttons()
예제 #11
0
    def __init__(self,
                 parent,
                 developer_id=None,
                 developer_name=None,
                 product_id=None,
                 product_name=None,
                 product_descr=None,
                 pwrdownmode=False):
        """
        Constructor
        
        @param parent: parent wizard
        @param developer_id: developer ID
        @param developer_nanme: developer name
        @param product_id: product ID
        @param product_nanme: product name
        @param product_descr: product description
        @param pwrdownmode: power-down mode
        """
        SwapWizardPage.__init__(self, parent, title="Product information")

        # Developer name
        self.developer_name = developer_name
        if self.developer_name is None:
            self.developer_name = ""
        # SWAP develoepr id
        self.developer_id = developer_id
        if self.developer_id is None:
            self.developer_id = ""
        # Product name
        self.product_name = product_name
        if self.product_name is None:
            self.product_name = ""
        # Product description
        self.product_descr = product_descr
        if self.product_descr is None:
            self.product_descr = ""
        # SWAP peoduct id
        self.product_id = product_id
        if self.product_id is None:
            self.product_id = ""
        # Battery-powered device
        self.low_power = pwrdownmode

        # Add widgets to the page
        self.add_to_layout(
            wx.TextCtrl(self,
                        -1,
                        validator=TextValidator(self, "developer_name"),
                        size=(150, 26)), "Developer name")
        self.add_to_layout(
            wx.TextCtrl(self,
                        -1,
                        validator=TextValidator(self,
                                                "developer_id",
                                                regex="^[0-9]*$"),
                        size=(70, 26)), "Developer ID number (DEC)")
        self.add_to_layout(
            wx.TextCtrl(self,
                        -1,
                        validator=TextValidator(self,
                                                "product_name",
                                                regex="^[a-zA-Z0-9]*$"),
                        size=(150, 26)), "Product name (single word)")
        self.add_to_layout(
            wx.TextCtrl(self,
                        -1,
                        validator=TextValidator(self, "product_descr"),
                        size=(250, 26)), "Product description")
        self.add_to_layout(
            wx.TextCtrl(self,
                        -1,
                        validator=TextValidator(self,
                                                "product_id",
                                                regex="^[0-9]*$"),
                        size=(70, 26)), "Product ID number (DEC)")
        self.add_to_layout(
            wx.CheckBox(self,
                        -1,
                        "Battery-powered device?",
                        validator=BoolValidator(self, "low_power")))

        self.Bind(wx.wizard.EVT_WIZARD_PAGE_CHANGING, self.onpage_changing)
예제 #12
0
 def is_valid(self, value):
     return all(TextValidator.is_valid(value) for TextValidator in self.all_validators)
예제 #13
0
 def __init__(self, validators=None):
     self.default_validator = [TextValidator(1001, 3000)]
     self.all_validators = self.default_validator
     if isinstance(validators, list) and validators:
         self.all_validators += validators
     super().__init__()
예제 #14
0
 def __init__(self, validators=None):
     self.default_validators = [TextValidator(0, 999)]
     self.all_validators = self.default_validators
     if isinstance(validators, list) and validators:
         self.all_validators += validators
예제 #15
0
 def setUp(self) -> None:
     self.min_length = 16
     self.max_length = 256
     self.validator = TextValidator()
예제 #16
0
 def setUp(self) -> None:
     minimal = randint(0, 128)
     maximal = randint(128, 256)
     self.min_length = minimal
     self.max_length = maximal
     self.validator = TextValidator(min_length=minimal, max_length=maximal)
예제 #17
0
    def __init__(self, validators=None):
        self.default_validator = [TextValidator(min_length=0, max_length=999)]
        self.all_validators = self.default_validator

        if isinstance(validators, list) and validators:
            self.all_validators += validators
예제 #18
0
 def __init__(self, validators=None, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.default = [TextValidator(min_length=1001, max_length=3000)]
     self.all_validators = self.default
     if isinstance(validators, list) and validators:
         self.all_validators += validators