I'm trying to do a pytest on a function without return value, but obviously value is None in pytets. I was wondering if there is a solution for that?
here is function which I'm trying to test:
def print_top_movies_url():
for item in movie_link[:100]:
print item.contents[1]
The best thing to do would be to separate getting the top movies and printing them.
For example, you could have a top_movie_urls which looks like this:
def top_movie_urls():
urls = []
for item in movie_link[:100]:
urls.append(item.contents[1])
return urls
(or make it a generator function)
That's easy to test, and wherever you call it, you can now just do something like print('\n'.join(top_movie_urls())).
If you really want to test the output instead, you can use pytest's output capturing to access the output of the tested function and check that.
Related
im really new to scala and gatling testing. What im trying to do is to extract parameters from response and save it to some session variabels. I want to pass map with variable name, and variable path to be extracted.
if(req.method == "GET"){
scn.exec(http(req.url).get("/uri").check(checkIf(!req.additionalParameters.isEmpty){
for(par <- additonalParameters){
jsonPath(par._2).saveAs(par._1)
}
}))
}
Im was trying something like this, but it dosen't compile and im wondering if it's even possible to do.
Thanks for all the help :)
That's not possible this way atm (as of Gatling 3.3.1), checkIf second parameter takes one single value. You need one checkIf per check.
I'm new to Gatling and Scala, and I had a hopefully quick and basic question about how to access the elements that are saved as from a findAll in the previous request.
The regex in the below code matches multiple button values. I eventually want to find the "max" button value (by something I'll come up with later), and based on that use that button in subsequent requests. However, I'm unable to actually access the values in button_list. In the terminal when I try to print the values, the values don't get substituted and literally print like this for each button:
Button ${count}: ${button}
Button ${count}: ${button}
Here's the snippet producing this:
...
.exec(http("click_ok")
.post("www.foo.com")
.headers(headers_0)
.formParam("_flowExecutionKey", "${flow_execution_key}")
.formParam("_eventId_submit", "${_eventId_submit}")
.check(regex("""foo(.*?)bar""").findAll.saveAs("button_list"))).exitHereIfFailed
.pause(1)
.foreach("${button_list}", "button", "count") {
exec(session => {
println("Button ${count}: ${button}")
session})
}
...
When I see the session print out in the logs, I can see that the buttons have matched and the session contains a list like the following, so I know there are successful matches:
button_list -> List(c11/98/280, c11/98/390)
Anyone have an example or know what I'm doing wrong?
Thanks!
As explained in the official documentation, Gatling Expression Language is not something that magically works anywhere. It only works when passing such String to a Gatling DSL method, not in your own code. You must use the Gatling Session API.
I am using python-click and I would like to pass values with a format like this
myprogram mycommand --parameter param1=value1 --parameter param2=value2
I was looking at click option documentation but I can't find any construct that could help with this, the only solution I can find is invoking a callback function and check that the string is properly constructed <key>=<value>, then elaborate the values properly.
Nothing bad in that solution, but I was wondering if there is a more elegant way to handle this since the pattern looks to be common enough.
So, I've had a go at it. I've managed to do it the following ways.
Firstly, I've tried this, though it doesn't satisfy the --parameter criteria.
#click.command("test")
#click.argument("args", nargs=-1)
def test(args):
args = dict([arg.split("=") for arg in args])
print(args)
so when invoking like test param1=test1 param2=test the output is:
{'param1': 'test1', 'param2': 'test2' }
Secondly, I thought about a multiple option, combined with a variadic argument, which seems to be closer to your requirements:
test -p param1=test -p param2=test
#click.command("test")
#click.option('-p', '--parameter', multiple=True)
#click.argument("args", nargs=-1)
def test(*args, **kwargs):
param_args = kwargs['parameter']
param_args = dict([p.split('=') for p in param_args])
print(param_args)
if __name__ == '__main__':
test()
The output will be the same as the previous case.
If you were to print(kwargs['parameter']), you'd get
('param1=test', 'param2=test')
It sounds a bit more cleaner than using a callback, but not by much. Still, hope it helps.
I have these very simple lines of code:
var friends = ["Mike", "Marika", "Andreas", "Peter", "Sabine"]
friends.map{
println("Hallo \($0)!")
}
This works fine in a program but I get no output in a playground.
It only tells me the count of the elements and how many times to function needs to run. But it does not write the strings.
Is it me or is this a bug in Xcode?
It's not a bug in Xcode. While your map code will print to the standard out (hit cmd-opt-enter to reveal the output in the assistant editor on the right), stylistically you should avoid using map for this. You would be better off with a for...in loop:
for friend in friends {
println("Hallo \(friend)")
}
If you quick-look the results this time, you'll see a more helpful result:
(note, I've switched the quick look to the list view, which shows every result, rather than just the last one)
Why is this working differently? It's because map isn't really for running arbitrary code against your array. It's more specifically for transforming (i.e. mapping) your array into another array. So suppose instead of printing a list of friends, you wanted a list of greetings, you could do this:
let greetings = friends.map { friend in
"Hallo \(friend)"
}
greetings will now be set to a new array of 5 strings, one for each name, of the form "Hallo <name>". map is taking a closure that takes a string, and maps it to a new string.
So what is happening when you write friends.map { println("...") } is that map is calling the closure, and getting the result of the expression in the closure, and populating a new array with it. Since println returns Void, the result of that expression each time is Void. And it is that Void that Xcode is displaying (as "(0 elements)" which is how the UI displays Void).
Instead, with the for-loop, Xcode knows that a stand-alone println who's value isn't being used should be interpreted not as a result, but as what got output to the standard out, so that's what it does.
i had a code that c send back 1 number (mex)
the matlab code was
vMsg=unit32(Gateway_test_app(2))
now i added 1 more return value to Gateway_test_app(2) which is s STRING
what i need to do to get the two values back
i was thinking about something like this:
[vMsg,errMsg]=??????(Gateway_test_app(2))
what should i put in the ????? place?
thx for any help
johnny.
ps
using codegen and need not to get err when building
First call the function and store the two outputs, then run your extra function unit32 (what does it do, by the way?) on the first output only:
[vMsgOriginal, errMsg] = Gateway_test_app(2);
vMsg = unit32(vMsgOriginal);
This assumes that you don't want to process your new string output through your unit32 function.