test-fullautomation / python-jsonpreprocessor

A preprocessor for json files
Apache License 2.0
2 stars 2 forks source link

Validity pre-check for variable names to be introduced #206

Open test-fullautomation opened 4 months ago

test-fullautomation commented 4 months ago

Validity pre-check for variable names need to be introduced.

validity check of variable names

Goal is to have early error messages if the parameter contains not allowed characters.

Error message should be e.g.

Parameter name xyz is invalid. Expected format: <current_regexp>.

Out of this description generated code fragment:


class VariableNameChecker:
    def __init__(self, regex=r'^[a-zA-Z_][a-zA-Z0-9_]*$'):
        self.regex = regex

    def check_variable_name(self, variable_name):
        if re.match(self.regex, variable_name):
            return True
        else:
            print(f"Error: Parameter name '{variable_name}' is invalid. Expected format: '{self.regex}'")
            return False

# Example usage:
checker = VariableNameChecker()

# Valid variable name
checker.check_variable_name("my_variable")

# Invalid variable name
checker.check_variable_name("2_variable")
namsonx commented 3 months ago

allows any key names that are allowed by JSON

test-fullautomation commented 3 months ago

Hi Son, as discussed. The idea is that jsonpreprocessor validates key names by default against JSON specification. If used by testsuites-management, then you need to hand-over a new regexp which validates key names against RobotFramework core specification for variable names. Thank you, Thomas

namsonx commented 2 months ago

Hello Thomas,

I pushed the new commit 4dc80cfc2b6a to check key names of jsonp file, this validation is based on the key name rules of JSON. This will check is there any control characters in key names of jsonp file.

Thank you, Son

HolQue commented 2 months ago

Please also consider:

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/262

HolQue commented 2 months ago

I am confused. In the JsonPreprocessor code I cannot find the class VariableNameChecker mentioned above. Also in TestsuitesManagement I cannot find the possibility to overwrite the default regular expression by a regular expression for parameter names, that is specific for the TestsuitesManagement.

What does this mean? Is this part of the concept not wanted any more? Or not required any more? Does this mean that there are no differences between JsonPreprocessor requirements and TestsuitesManagement requirements w.r.t. parameter names?

HolQue commented 2 months ago

What is the status of this CRQ?

I can do this:

"------------" : 123,
"param" : {"------------" : 456}

And I get:

{'------------': 123, 'param': {'------------': 456}}

If such a name is allowed, it should be possible to use this on the right hand side of the colon - to get access to the value.

But

"param" : ${------------}

causes

Error: 'Expression '${------------}' cannot be evaluated. Reason: A pair of curly brackets is empty or contains not allowed characters.'!

The same in quotes:

"param" : "${------------}"

works:

{'------------': 123, 'param': '123'}

What does this mean now: Shall such characters like minus characters be allowed inside key names or not?

HolQue commented 2 months ago

See also:

https://github.com/test-fullautomation/python-jsonpreprocessor/issues/278

test-fullautomation commented 2 months ago

Hi Son,

Task is still valid. Implementation is expected in jsonpreprocessor. Ticket is also here located. Testsuitesmanagement shall handover regexp requirement as per Robot Framework.

We need to talk again about the requirement. Seems to be some confusion here.

Don't change for 0.11.n anymore. Rest we do in 0.12.n

Thank you, Thomas