PowerMockito error: Cannot access Stubber/IOngoingStubbing - powermockito

The IDE compiler shows these errors when using PowerMockito.
I tried both variants for specifying return values:
Variant 1
doReturn(jsonString).when(MyStaticClass.myStaticMethod());
Variant 2
when(MyStaticClass.myStaticMethod()).thenReturn(jsonString);
Why do the compiler display these errors?

I used
import static org.powermock.api.mockito.PowerMockito.when;
but you should use:
import static org.mockito.Mockito.when;

Related

mpi4py Split_type using openmpi's OMPI_COMM_TYPE_SOCKET

Is it possible to split a communicator using openmpi's OMPI_COMM_TYPE_SOCKET in mpi4py?
I've verified this works:
from mpi4py import MPI
comm = MPI.COMM_WORLD
sharedcomm = comm.Split_type(MPI.COMM_TYPE_SHARED)
but this does not:
socketcomm = comm.Split_type(MPI.OMPI_COMM_TYPE_SOCKET)
nor does this:
socketcomm = comm.Split_type(MPI.COMM_TYPE_SOCKET)
I've looked at the docs but I can't find anything about this.
mpi4py only provides a wrapper around standard MPI features. OMPI_COMM_TYPE_SOCKET is an Open MPI specific split type. You may still use it in mpi4py if you know its numeric value as it is just a member of a C enum:
/*
* Communicator split type constants.
* Do not change the order of these without also modifying mpif.h.in
* (see also mpif-common.h.fin).
*/
enum {
MPI_COMM_TYPE_SHARED,
OMPI_COMM_TYPE_HWTHREAD,
OMPI_COMM_TYPE_CORE,
OMPI_COMM_TYPE_L1CACHE,
OMPI_COMM_TYPE_L2CACHE,
OMPI_COMM_TYPE_L3CACHE,
OMPI_COMM_TYPE_SOCKET, // here
OMPI_COMM_TYPE_NUMA,
OMPI_COMM_TYPE_BOARD,
OMPI_COMM_TYPE_HOST,
OMPI_COMM_TYPE_CU,
OMPI_COMM_TYPE_CLUSTER
};
#define OMPI_COMM_TYPE_NODE MPI_COMM_TYPE_SHARED
Being a member of an enum means that the actual numerical value of OMPI_COMM_TYPE_SOCKET depends on its position in the enum and hence may differ from one release of Open MPI to another. You have several options here.
Hardcode the value
This is the simplest option. Open mpi.h (ompi_info --path incdir gives you its location), count the position of OMPI_COMM_TYPE_SOCKET in the enclosing enum starting with 0 for MPI_COMM_TYPE_SHARED and hardcode the value. The code may break with releases of Open MPI different from yours.
Parse mpi.h
Read mpi.h, search for enum definitions and find the one containing OMPI_COMM_TYPE_SOCKET. Provided that MPI_COMM_TYPE_SHARED is 0, the value of OMPI_COMM_TYPE_SOCKET is its 0-based index in the sequence of enum values. This depends a lot on the code in mpi.h having a specific format and can easily break if that changes.
Parse mpif.h
The Fortran interface is easier to parse as there the value is defined as:
parameter (OMPI_COMM_TYPE_SOCKET=6)
This is easily parsable with a simple regular expression. The problem is that recent versions of Open MPI split mpif.h over a couple of files that are then included from mpif.h and currently the value is in mpif-constants.h. So you may need to parse the include statements and recurse into the files they reference. Note that those are Fortran include statements and not preprocessor #include directives.
Code generation
Write a small C program that outputs the value of OMPI_COMM_TYPE_SOCKET to a Python file and run it as part of your program's setup procedure. Something like:
#include <stdio.h>
#include <mpi.h>
int main (int argc, char **argv)
{
if (argc != 2)
{
printf("Usage: mkompimod /path/to/module.py\n");
return 1;
}
FILE *fh = fopen(argv[1], "w");
if (fh != NULL) {
fprintf(fh, "COMM_TYPE_SOCKET = %d\n", OMPI_COMM_TYPE_SOCKET);
fclose(fh);
}
return 0;
}
Put that in a file named mkompimod.c. Compile with mpicc -o mkompimod mkompimod.c and run with mkompimod /path/to/ompi.py to create a Python file ompi.py with the value of OMPI_COMM_TYPE_SOCKET. Import it and use it in the call to comm.Split_type():
import ompi
socketcomm = comm.Split_type(ompi.COMM_TYPE_SOCKET)
Write a Python module in C
That's a bit involved, but you can write a C module that includes mpi.h and exports the value of OMPI_COMM_TYPE_SOCKET as a Python constant. Consult the Python documentation on how to write extensions in C.
Use the CFFI module
CFFI lets you build Python modules that wrap C libraries and writes all the glue code for you. Put the following in a file named ompi_build.py:
from cffi import FFI
ffi = FFI()
ffi.set_source("ompi", r"#include <mpi.h>")
ffi.cdef(
r"""
const int OMPI_COMM_TYPE_HWTHREAD;
... more constants here ...
const int OMPI_COMM_TYPE_SOCKET;
... even more constants here ...
"""
)
if __name__ == "__main__":
ffi.compile(verbose=True)
Run like this:
$ CC=mpicc python ompi_build.py
This will create the C module ompi.c and compile it into a loadable DSO. You may then import it and access the constant like this:
from ompi.lib import OMPI_COMM_TYPE_SOCKET
socketcomm = comm.Split_type(OMPI_COMM_TYPE_SOCKET)
CFFI provides integration with Python's distutils and you can have it automatically build the C module as part of the setup process.
Use Cython
That's what mpi4py itself is written in. It blends C and Python into a single cryptic syntax. Read the source code. Try to figure out what's going on and how to write something yourself. Can't help you there.
Whichever path you choose, keep in mind that all this pertains to the system on which the program will be running, not only the system on which the program will be developed.

How to add a python module which uses Sel2Lib without getting multiple keyword error?

I'm trying to import a python module to ride for more than 3 hours with no success. I went through the steps explained in fourth answer here where it suggests to create a python module Selenium2LibraryExt.
How to get All Text in robot framework ?
the problem that i observe is that since i use Selenim2Library in my other codes of the same test now i import Selenium2LibraryExt which inherits from Selenim2Library, my test doesn't know anymore that e.g. Click Element keyword comesfrom Selenim2Library or Selenium2LibraryExt and it gives me multiple keyword error
So i did
1-I removed
from Selenium2Library import Selenium2Library
from the head of my python module but i let it stay as a library in my test case: settings
Library Selenium2Library
it didn't work out. 2-Then i removed
Library Selenium2Library
from my test case but added:
from Selenium2Library import Selenium2Library
in the head of my python module.
but in both cases i get errors. how should i do not to have 2 selenium2library libraries seen by my test?
Thanks
If you go with a library that inherits, then your test data needs to import either Selenium2Library or your custom library, but not both. If you only import through a shared resource file, and not directly in the tests, this is easier to control.
Another option is to create a library that extends Selenium2Library without replacing it:
from robot.libraries.BuiltIn import BuiltIn
class Selenium2LibraryExt(object):
#property
def _s2l(self):
return BuiltIn().get_library_instance('Selenium2Library')
def get_all_texts(self, locator):
"""Returns the text values of elements identified by `locator`."""
elements = self._s2l._element_find(locator, False, True)
return [e.text for e in elements]
If you are using a recent version of Selenium2Library (>= 1.7), Get Webelement and Get Webelements allow you to do a lot of things there are not keyword for...
#{texts} Create List
#{elems} Get Webelements some locator
:FOR ${elem} IN #{elems}
\ ${text} Get Text ${elem}
\ Append To List ${texts} ${text}
Same thing but getting the text using the extended variable syntax to work with a webelement.
#{texts} Create List
#{elems} Get Webelements some locator
:FOR ${elem} IN #{elems}
\ Append To List ${texts} ${elem.text}
Or in Python:
from robot.libraries.BuiltIn import BuiltIn
class Selenium2LibraryExt(object):
def get_all_texts(self, locator):
"""Returns the text values of elements identified by `locator`."""
s2l = BuiltIn().get_library_instance('Selenium2Library')
elements = s2l.get_webelements(locator)
# or elements = BuiltIn().run_keyword('Get Webelements', locator)
return [e.text for e in elements]
See also https://stackoverflow.com/a/35323931/2532697
So you can easily get around this by specifying the particular library you want to use. For example:
Selenium2LibraryExt.Click Element

getMethodASTEclipse() returns undeclared variable

I am completely new to Rascal and am trying to create ASTs from an eclipse project using the following code
Module FirstTryAST
import lang::java::m3::Core;
import lang::java::jdt::m3::Core;
import Set;
import Relation;
import IO;
import List;
import Map;
import Exception;
import ParseTree;
void test(){
M3 myModel = createM3FromEclipseProject(|project://MyProject/|);
println("Loaded M3 model, looping through methods..");
for(m <- methods(model)) mAST = getMethodASTEclipse(m);
println("Success");
}
When the program (run in eclipse Rascal Console) tries to execute
getMethodASTEclipse(m);
it returns:
|plugin://rascal_eclipse/src/org/rascalmpl/eclipse/library/lang/java/jdt/m3/Core.rsc|(1238,18,<40,12>,<40,30>):
Undeclared variable: getModelContaining
How do I get around this / what did I do wrong ?
I am using Eclipse Mars on Ubuntu 15.04 (Cinnamon).
If you need more information, please let me know.
Update:
When I use getMethodASTEclipse(m, model = myModel) it works fine.
Although this workaround works for me, I still would like to know the answer on why I get this undeclared variable message.
This has been translated into an issue on github. This was a bit of an unused function, and I think we will delete it.
To get the AST use either lang::java::jdt::m3::AST::createAstsFromEclipseProject or lang::java::jdt::m3::AST::createAstsFromEclipseFile. With rascal pattern matching you can find the methods inside.

getProperty & getSystemProperty in MonkeyRunner return None

I'm new to Android development and test, currently I'm training to make a test scripts under Python and then use monkeyrunner to run them.
As said in MonkeyDevice official documentation , the [getProperty()][1] and [getSystemProperty()][2] should return you a value that depends on property variable name you pass for them. Each time I got only 'None' value. Any idea or trick?!
The simple code I'm using :
from com.android.monkeyrunner import MonkeyDevice,MonkeyRunner
device = MonkeyRunner.waitForConnection()
print device.getSystemProperty('version.sdk')
Regards,,,
You need to specify the property group. For example:
print device.getSystemProperty('build.version.sdk')
for whatever reason both getProperty() and getSystemProperty() don't work for me but you can run:
$ adb shell getprop
which returns a complete list of attributes/values

Flex compile problem with as3httpclient

I am having trouble getting a Flex application (with as3httpclient) to work.
I compiled it (compc -load-config=build-swc.xml), put the as3httpclientlib-1_0_6.swc in my libs dir, and ran
mxmlc -compiler.include-libraries lib/as3crypto-1_3_patched.swc
lib/as3httpclientlib-1_0_6.swc lib/corelib.swc -- App.mxml
In my actionscript I
import org.httpclient.HttpClient;
but still I receive the error
Error: Type was not found or was not a compile-time constant: HttpStatusEvent
client.listener.onStatus = function(event:HttpStatusEvent):void {
...
. Any ideas?
btw / before compiling "compc -load-config=build-swc.xml" I hade to
change
<path-element>${flexlib}/libs/player/9/playerglobal.swc</path-element>
to
<path-element>${flexlib}/libs/player/10.0/playerglobal.swc</path-element>
in order for it to compile because my flex version doesn't have a playerglobal.swc for Flash 9. 8o
Unless this is a custom defined class, there is no such thing as HttpStatusEvent, you need to import flash.events.HTTPStatusEvent and refer to it as such.

Resources