예제 #1
0
    def test_regex_flags(self):
        pdv = RegexParameter("foo",
                             r'.+foo=(\d+).+',
                             lambda match: int(match.group(1)),
                             lambda x: str(x),
                             regex_flags=re.DOTALL,
                             value=12)
        # Assert something good with dotall update()
        self.assertTrue(pdv)
        pdv.update("\n\nfoo=1212\n\n")
        self.assertEqual(pdv.get_value(), 1212)

        # negative test with no regex_flags
        pdv = RegexParameter("foo",
                             r'.+foo=(\d+).+',
                             lambda match: int(match.group(1)),
                             lambda x: str(x),
                             value=12)
        # Assert something good with dotall update()
        self.assertTrue(pdv)
        pdv.update("\n\nfoo=1212\n\n")
        self.assertEqual(pdv.get_value(), 12)

        self.assertRaises(TypeError,
                          RegexParameter,
                          "foo",
                          r'.*foo=(\d+).*',
                          lambda match: int(match.group(1)),
                          lambda x: str(x),
                          regex_flags="bad flag",
                          value=12)
    def test_regex_flags(self):
        pdv = RegexParameter("foo",
                             r'.+foo=(\d+).+',
                             lambda match: int(match.group(1)),
                             lambda x: str(x),
                             regex_flags=re.DOTALL,
                             value=12)
        # Assert something good with dotall update()
        self.assertTrue(pdv)
        pdv.update("\n\nfoo=1212\n\n")
        self.assertEqual(pdv.get_value(), 1212)

        # negative test with no regex_flags
        pdv = RegexParameter("foo",
                             r'.+foo=(\d+).+',
                             lambda match: int(match.group(1)),
                             lambda x: str(x),
                             value=12)
        # Assert something good with dotall update()
        self.assertTrue(pdv)
        pdv.update("\n\nfoo=1212\n\n")
        self.assertEqual(pdv.get_value(), 12)

        self.assertRaises(TypeError,
                          RegexParameter,
                          "foo",
                          r'.*foo=(\d+).*',
                          lambda match: int(match.group(1)),
                          lambda x: str(x),
                          regex_flags="bad flag",
                          value=12)
예제 #3
0
    def test_mixed_pdv_types(self):
        """ Verify we can add different types of PDVs in one container """
        self.param_dict.add_parameter(
            FunctionParameter("fn_foo",
                              self.pick_byte2,
                              lambda x: str(x),
                              direct_access=True,
                              startup_param=True,
                              value=1,
                              visibility=ParameterDictVisibility.READ_WRITE))
        self.param_dict.add_parameter(
            RegexParameter("foo",
                           r'.*foo=(\d+).*',
                           lambda match: int(match.group(1)),
                           lambda x: str(x),
                           direct_access=True,
                           startup_param=True,
                           value=10,
                           visibility=ParameterDictVisibility.READ_WRITE))
        self.param_dict.add("bar",
                            r'.*bar=(\d+).*',
                            lambda match: int(match.group(1)),
                            lambda x: str(x),
                            direct_access=False,
                            startup_param=True,
                            value=15,
                            visibility=ParameterDictVisibility.READ_WRITE)

        self.assertEqual(self.param_dict.get("fn_foo"), 1)
        self.assertEqual(self.param_dict.get("foo"), 10)
        self.assertEqual(self.param_dict.get("bar"), 15)
예제 #4
0
 def test_regex_val(self):
     pdv = RegexParameter("foo",
                          r'.*foo=(\d+).*',
                          lambda match: int(match.group(1)),
                          lambda x: str(x),
                          value=12)
     self.assertEqual(pdv.get_value(), 12)
     result = pdv.update(1)
     self.assertEqual(result, False)
     self.assertEqual(pdv.get_value(), 12)
     result = pdv.update("foo=1")
     self.assertEqual(result, True)
     self.assertEqual(pdv.get_value(), 1)
 def test_regex_val(self):
     pdv = RegexParameter("foo",
                          r'.*foo=(\d+).*',
                          lambda match: int(match.group(1)),
                          lambda x: str(x),
                          value=12)
     self.assertEqual(pdv.get_value(), 12)
     result = pdv.update(1)
     self.assertEqual(result, False)
     self.assertEqual(pdv.get_value(), 12)
     result = pdv.update("foo=1")
     self.assertEqual(result, True)
     self.assertEqual(pdv.get_value(), 1)