Any way to create dict using table so key/values can be text aligned in file?

982 views
Skip to first unread message

Hawkman

unread,
Dec 23, 2015, 12:20:15 PM12/23/15
to robotframework-users, pm...@kmpc.net
New to RF and really love the power of the system.

I see in the BuiltIn lib doc it now has the 'Create Dictionary' keyword.  It is also states:

This keyword was changed in Robot Framework 2.9 in many ways:

  • Moved from Collections library to BuiltIn.
  • Support also non-string keys in key=value syntax.
  • Deprecated old syntax to give keys and values separately.
  • Returned dictionary is ordered and dot-accessible.
I have a need to create a 'data base' of values for my testing project using lists and dicts.  When these are long I like to text align the key and values.  But either spaces are not allowed between the key/value and the = sign (in the Variables section)  or in the table cells in test cases when using the 'Create Dictionary' keyword a space becomes part of the value of the key (from what I can tell in my testing)

Examples

Turn this:

*** Variables ***
&{std input tests}           Typical Description=Lights out lab 2
...                   Shortest Alpha Description=P
...                 Shortest Numeric Description=9
...                        Max Alpha Description=abcdefghijklmnopqrstuvwx
...                      Max Numeric Description=123456789012345678901234


or this:

*** Variables ***
&{std input tests} Typical Description=Lights out lab 2
...                Shortest Alpha Description=P
...                Shortest Numeric Description=9
...                Max Alpha Description=abcdefghijklmnopqrstuvwx
...                Max Numeric Description=123456789012345678901234


to something like this:

*** Variables ***
&{std input tests} Typical Description                    = Lights out lab 2
...                Shortest Alpha Description   = P
...                Shortest Numeric Description = 9
...                Max Alpha Description                = abcdefghijklmnopqrstuvwx
...                Max Numeric Description            = 123456789012345678901234

Or alternatively turn this:

*** Test Cases***
Loop
On Dict
|    | ${std input tests}=  | Create Dictionary |
|    | ... | Typical Description=Lights out lab 2 |  
|    | ... | Shortest Alpha Description=P |  
|    | ... | Shortest Numeric Description=9 |
|    | ... | Max Alpha Description=abcdefghijklmnopqrstuvwx |
|    | ... | Max Numeric Description=123456789012345678901234 |
|    | ${tests}= | Get Dictionary Items | ${std input tests} |
|    | : FOR | ${test type} | ${test value} | IN | @{tests} |
|    |       | Log | ${test type}:${test value} |



to something like this:

*** Test Cases***
Loop
On Dict
|    | ${std input tests}=  | Create Dictionary |
|    | ... | Typical Description          | Lights out lab 2         |  
|    | ... | Shortest Alpha Description   | P                        |  
|    | ... | Shortest Numeric Description | 9                        |
|    | ... | Max Alpha Description        | abcdefghijklmnopqrstuvwx |
|    | ... | Max Numeric Description      | 123456789012345678901234 |
|    | ${tests}= | Get Dictionary Items | ${std input tests} |
|    | : FOR | ${test type} | ${test value} | IN | @{tests} |
|    |       | Log | ${test type}:${test value} |

I see I could use a reg ex from the String lib to post process the key/values in the test case examples but that seems over kill for just text alignment.

Thanks.

Tatu Aalto

unread,
Dec 23, 2015, 4:15:08 PM12/23/15
to Paul Hawkins, pm...@kmpc.net, robotframework-users

Ugh

Have you looked at variable files[1]? With variable files you can use any syntax supported by Python or YAML(with YAML, there might be some limitations). Of course, the bad side is that, then variable content is hidden in those files.

-Tatu
Send from my mobile
[1] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#variable-files

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Hawkman

unread,
Dec 23, 2015, 4:27:54 PM12/23/15
to robotframework-users, a.glue...@gmail.com, pm...@kmpc.net
I have looked at variable files before but not in this context.  That is a perfect solution.  Viability is not an issue for this problem.

Thx!
Reply all
Reply to author
Forward
0 new messages