Pari-gp znorder gives compile error - pari-gp

I run this simple query:
for(x=1,10, p=prime(x);a=Mod(100, p);print(a);print(znorder(a)))
This gives me:
Mod(0, 2)
*** at top-level: ...od(100,p);print(a);print(znorder(a));)
*** ^-------------
*** znorder: not an element of (Z/nZ)* in order.
*** Break loop: type 'break' to go back to GP
Replacing p by 3 run normally. What am I doing wrong?

I found it. The problem was where p divides 100, and then it's order is undefined.

Related

RobotFramework: empty variable check suddenly not working anymore

I'm playing around with command-line arguments and had something working both with / without giving a command-line argument, but suddenly it starts failing if I don't give a command-line argument.
On https://groups.google.com/g/robotframework-users/c/_5Usp-K4Dlw?pli=1 I read that adding a space before the variable and comparing it to a value like this '${ VAR}'==<value> should work to check if a variable is existing or not.
The code-snippet that was working before is:
*** Test Cases ***
My test
[Documentation] test to check if the SUT reacts as expected
${is_test}= Evaluate '${ VAR}'=='test'
Log To Console ${is_test}
Run Keyword If ${is_test} Log To Console VAR == test
After changing the code to (Removed '[Documentation]' since it was copied from another test):
*** Test Cases ***
My test
${is_test}= Evaluate '${ VAR}'=='test'
Log To Console ${is_test}
Run Keyword If ${is_test}
... Log To Console VAR == test
it suddenly started failing with: Variable '${ VAR}' not found. errors.
And after changing it back to the original it still fails.
I can't figure what I did wrong in the change.
Note: The company I'm working for uses RobotFramework version 3.0.4 (yes I know ancient)
Managed to solve it by adding ${VAR} with some default value to a *** Variables *** list. But still I don't understand why it was originally working without that list.
Here is how your test should look like if you want to check if variable is empty and do something based on that.
*** Variables ***
${VAR}= test
*** Test Cases ***
My test
Run Keyword If '${VAR}'=='${EMPTY}' Log To Console Variable is empty
... ELSE Log To Console Variable is not empty
If you want variable default value to be empty and execute some keyword only if it comes from command line set variable as empty, for example:
*** Variables ***
${VAR}= ${EMPTY}
*** Test Cases ***
My test
Run Keyword If '${VAR}'=='${EMPTY}' Log To Console Variable is not set
... ELSE Log To Console Variable is ${VAR}
Run your test from command-line without passing variable
$ robot sample.robot
==============================================================================
Sample
==============================================================================
My test Variable is not set
My test | PASS |
------------------------------------------------------------------------------
Sample | PASS |
1 test, 1 passed, 0 failed
==============================================================================
Now, run with passing variable
$ robot -v VAR:test sample.robot
==============================================================================
Sample
==============================================================================
My test Variable is test
My test | PASS |
------------------------------------------------------------------------------
Sample | PASS |
1 test, 1 passed, 0 failed
==============================================================================
P.S. About space inside variable, I think it's just typo in Google Groups. If it was working then variable might be globally accessible or defined somewhere else.

Template keywords can't handle line break in RF 3.2.1

This test case if working fine in Robot Framework 3.1.2 but in 3.2.1 I'm getting error message:
Setting 'Template' accepts only one value, got 2.
I can't see that there is any updates to the documentation that explains this. Any ideas?
*** Test Cases ***
Test Case
[Template] The result of ${calculation}
... should be ${expected}
1 + 1 2
2 + 2 4
*** Keywords ***
The result of ${calculation} should be ${expected}
${result} = Evaluate ${calculation}
Should Be Equal As Integers ${result} ${expected}
The ... marks an argument boundary. What you did is exactly the same as this:
[Template] The result of ${calculation} should be ${expected}
Like the error says, the [Template] setting only accepts a single argument but you're passing two. You cannot define the keyword on multiple lines.
It appears that the old (pre 3.2) parser may have been a bit lax and allowed you to split the template keyword on multiple lines. The new parser doesn't allow that.

Is it possible to give arguments inside variables in robot framework?

Library REST ${base_url}
*** Keywords ***
Get Requests
GET ${rest_of_the_url}
Output response body
*** Test Cases ***
Do some searching
Get Requests
*** Variables ***
${base_url} https://business.com
${rest_of_the_url} /api/${department}/${person_name}
How can I assign values to ${department} and ${person_name}? I don't want to set those inside Variables because then I cannot write multiple scenarios inside one .robot file. Is it possible to do the assignment as arguments?
i do not think there is a way to pass arguments within the variables,
The below section is straight from the documentation of Robotframework,
where you can create Variables inside variables
Variables inside variables
Variables are allowed also inside variables, and when this syntax is used, variables are resolved from the inside out. For example, if you have a variable ${var${x}}, then ${x} is resolved first. If it has the value name, the final value is then the value of the variable ${varname}. There can be several nested variables, but resolving the outermost fails, if any of them does not exist.
In the example below, Do X gets the value ${JOHN HOME} or ${JANE HOME}, depending on if Get Name returns john or jane. If it returns something else, resolving ${${name} HOME} fails.
*** Variables ***
${JOHN HOME} /home/john
${JANE HOME} /home/jane
*** Test Cases ***
Example
${name} = Get Name
Do X ${${name} HOME}
E.g.,
${person_name}= Set Variable Matt
${department}= Set Variable R&D
# then your code continues
${rest_of_the_url} /api/${department}/${person_name}
Set Variable documentation.
Try to see this using the Set Test / Suite / Global Variable keywords here:
https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
Use "Set Suite Variable" keyword then enter the variables $ {person_name} e
$ {department} inside * Variables * then you should read the value inside the test.

RF 3.0.4 nested dictionary syntax error if first key is number, dot notation doesn't work

I am using rf 3.0.4. I upgraded because of the dot notation upgrade (before I was using rf 2.9).
My problem is when I want to access a nested dictionary item and the first key (it is an id from db) is a number, I got a syntax error.
I have a nested dictionary: &{Attributes}
So what I want to do:
${Attributes.1000.name}
The syntax error I get:
Resolving variable '${Attributes.1000.name}' failed: SyntaxError: invalid syntax (<string>, line 1)
And what is working:
${Attributes["1000"]["name"]}
I'd like to use the dot notation, because it is more readable.
Do any of you know why it doesn't work?
It seems to me to be a limitation of Robot Framework. When a dictionary key item starts with a number (even when a string) then it will fail. In the below two test cases this is shown.
To me this sounds like a defect and you may want to log this as an issue with the project's GitHub issue log.
*** Settings ***
Library Collections
*** Variables ***
${name} MyName
&{person} name=${name}
&{person_valid} A1000=${person} A2000=${person}
&{person_invalid} 1000A=${person} 2000A=${person}
*** Test Cases ***
TC - Valid
${pers} Set Variable ${person_valid.A1000}
Dictionaries Should Be Equal ${pers} ${person}
${pers_name_1} Set Variable ${person_valid["A1000"]["name"]}
Should Be Equal As Strings ${pers_name_1} ${name}
${pers_name_2} Set Variable ${person_valid.A1000.name}
Should Be Equal As Strings ${pers_name_2} ${name}
TC - Fails
Run Keyword And Expect Error
... Resolving variable '\${person_invalid.1000A}' failed: SyntaxError: invalid syntax (<string>, line 1)
... Set Variable ${person_invalid.1000A}
Run Keyword And Expect Error
... Resolving variable '\${person_valid.1000A.name}' failed: SyntaxError: invalid syntax (<string>, line 1)
... Set Variable ${person_valid.1000A.name}

Use "run keyword if" to call a function with a string argument, but without altering the string

I ran into an odd issue so I wrote this example where I call "print ${dir}" twice:
*** Variables ***
${dir} = "c:\\temp"
*** Test Cases ***
Test
print ${dir}
run keyword if 1 == 1 print ${dir}
*** Keywords ***
print ${input1}
log to console \r${input1}
Output:
"c:\temp"
"c: emp"
What do I need to do to make "print ${dir}" print the same thing each time?
The problem stems from the fact you're using the embedded argument syntax. In order for robot to know what keyword to call, it must first do expansion of the variable before calling the keyword. That removes one layer of backslashes. Then, when your keyword passes what's left to the log to console keyword it sees \t as a tab character, which is why you see a tab character rather than the backslash and the letter "t".
One solution is to use traditional arguments rather than embedded arguments. The following example gives the same output for both times the keyword is called:
*** Variables ***
${dir} = "c:\\temp"
*** Test Cases ***
Test
print ${dir}
run keyword if 1 == 1 print ${dir}
*** Keywords ***
print
[Arguments] ${input1}
log to console \r${input1}
It seems to me that the Run Keyword If keyword does some additional escaping of the backslashes. By adding 1 more backslash you'll see it happen in the first example as well.
To overcome this issue is to switch from backslashes () to forward slashes (/). This works on both *nix and Windows based systems.
*** Variables ***
${dir} = "c:\\temp"
to
*** Variables ***
${dir} = "c:/temp"
This still makes a valid path on Windows. So functionally the path reference will work as well.

Resources