generating test report using html test runner in sikuli - sikuli

I have read that we can generate test reports in sikuli using HTML test runner.
I have installed SIKULI X and have script for which I want to generate reports.
Is there any particular version of html test runner I need to install for this version of Sikuli ?
I have downloaded the "html-testRunner-1.0.3.tar.gz (md5)" from the path "https://pypi.python.org/pypi/html-testRunner".
Can anyone guide me on how I should install and integrate the same to my script ?

For me, I downloaded HTMLTestRunner.py from this website and put somewhere in my computer. Say if I put it in ~/Downloads/HTMLTestRunner folder, I just need to tell my sikulix program to find the path into that folder, and import HTMLTestRunner afterwards. This part is as follows:
import sys
_path = r"Downloads/HTMLTestRunner"
sys.path.append(_path)
import HTMLTestRunner
After that, everything goes as usual. Lemme try to make one example below.
import unittest
import sys
_path = r"Downloads/HTMLTestRunner"
sys.path.append(_path)
import HTMLTestRunner
class TestDemo(unittest.TestCase):
def testA(self):
assert True
def testB(self):
assert False
class TestDemo2(unittest.TestCase):
def testC(self):
assert True
def testD(self):
assert True
def suite():
suite = unittest.TestSuite()
# TestDemo
suite.addTest(TestDemo('testA'))
suite.addTest(TestDemo('testB'))
# TestDemo2
suite.addTest(TestDemo2('testC'))
suite.addTest(TestDemo2('testD'))
return suite
if __name__ == "__main__":
suite = suite()
unittest.TextTestRunner(verbosity=2)
output = open("results.html", 'w')
runner = HTMLTestRunner.HTMLTestRunner(stream=output, title='Test Report', description='This is a test')
runner.run(suite)
When you run it, you will get the following report
Hope it helps

Related

Stable-Baselines make_vec_env() not calling the wrapper kwargs as expected

I have a custom gym environment where I am implementing action masking. The code below works well
from toyEnv_mask import PortfolioEnv # file with my custom gym environment
from sb3_contrib import MaskablePPO
from sb3_contrib.common.wrappers import ActionMasker
from stable_baselines3.common.vec_env import DummyVecEnv
from stable_baselines3.common.env_util import make_vec_env
from sb3_contrib.common.maskable.utils import get_action_masks
env = PortfolioEnv()
env = ActionMasker(env,action_mask_fn=PortfolioEnv.action_masks)
env = DummyVecEnv([lambda: env])
model = MaskablePPO("MlpPolicy", env, gamma=0.4, verbose=1, tensorboard_log="./MPPO_tensorboard/")
...
i want to parallelize this and I am trying to use the make_vec_env() class. This sets up ok and starts running, but it does not respect the action masks anymore. This is the line i am using to replace the 3 lines above where i initialize the env.
env = make_vec_env(PortfolioEnv, wrapper_class=ActionMasker,wrapper_kwargs={'action_mask_fn':PortfolioEnv.action_masks} ,n_envs=2)
Any suggestions / help would be greatly appreciated.
i was making it unnecessarily complicated.
a simple env = make_vec_env(PortfolioEnv,n_envs=16) works
and the 3 lines that were working previously could have been just
env = PortfolioEnv()
env = DummyVecEnv([lambda: env])

How to modify the code so that i do not have to uninstall pycharm?

I have run the code as part of exception handling in python, during a session on Plural-sight but now even if a write a incorrect code the result is OK.
For example : hello world without print statement gives me exit code 0
Could you please advice on it?
code :
try:
import msvcrt
def getkey():
return msvcrt.getch()
except ImportError:
import sys
import tty
import termios
def getkey():
fd=sys.stdin.fileno()
original_attributes =termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, original_attributes)
return ch
You need to make sure that the indentation of your code is correct first.
For example get_key function should be defined in both: the try case and in the catch, in the catch case you indented it correctly under the catch statement, but for the try case you made it on the same level of indentation as the try itself, for the interpreter it means that the function definition is not related to the try you wrote, therefore it throws an error as you should not add code after between the try and catch statement.
a rewrite of your program
try:
import msvcrt
def getkey():
return msvcrt.getch()
except ImportError:
import sys
import tty
import termios
def getkey():
fd=sys.stdin.fileno()
original_attributes =termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, original_attributes)
return ch
This code says now, if we tried to import the library msvcrt and succeeded, then we will define a function get_key using the library, if failed; then we will define it again without using the library.

Pact.io, Junit - How to test againts multiple consumers with different tags?

I have multiple (not only junit) consumer applications, which create pacts in pact broker.
These consumers have many different git branches - e.g.:
consumer1: release123, release007, release999
consumer2: release69, release420, release50
Question
how to run provider tests against specific combinations of consumers and their tags?
e.g. consumer1 release007, consumer2 release69 AND release50 ?
is these something like -Dpactbroker.consumers=consumer1:release007,consumer2:release69,consumer2:release50 ?
I especially need this for junit, as we mostly use java apps as providers.
What I have found:
in junit, there is annotation #PactBroker which allows you to specify tags and consumers
according to description, these can be set via system properties pactbroker.tags and pactbroker.consumers
there can be specified multiple of each, separated by comma - e.g.: -Dpactbroker.consumers=consumer1,consumer2
I havent found if tags and consumers can be paired while running provider tests
Please try below solution might be it will help
You can add like below on Provider Class
API used
import au.com.dius.pact.provider.junit.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit.State;
import au.com.dius.pact.provider.junit.loader.PactBroker;
import au.com.dius.pact.provider.junit.loader.PactBrokerAuth;
import au.com.dius.pact.provider.junit.loader.PactFolder;
import au.com.dius.pact.provider.junit.target.Target;
import au.com.dius.pact.provider.junit.target.TestTarget;
import au.com.dius.pact.provider.spring.SpringRestPactRunner;
import au.com.dius.pact.provider.spring.target.SpringBootHttpTarget;
Provider Added on Class
#IgnoreNoPactsToVerify
#PactBroker(
authentication = #PactBrokerAuth(password = "*******", username = "********"),
host = "*******",
tags = {"test", "dev", "latest"},
port = "*****",
failIfNoPactsFound = false,
protocol = "http")
On consumer end you can add on each test case like below
API used
import au.com.dius.pact.consumer.Pact;
import au.com.dius.pact.consumer.PactProviderRuleMk2;
import au.com.dius.pact.consumer.PactVerification;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.model.RequestResponsePact;
Test Case Level
#Pact(consumer = "consumer-service-name")

How can I register a custom environment in OpenAI's gym?

I have created a custom environment, as per the OpenAI Gym framework; containing step, reset, action, and reward functions. I aim to run OpenAI baselines on this custom environment. But prior to this, the environment has to be registered on OpenAI gym. I would like to know how the custom environment could be registered on OpenAI gym? Also, Should I be modifying the OpenAI baseline codes to incorporate this?
You do not need to modify baselines repo.
Here is a minimal example. Say you have myenv.py, with all the needed functions (step, reset, ...). The name of the class environment is MyEnv, and you want to add it to the classic_control folder. You have to
Place myenv.py file in gym/gym/envs/classic_control
Add to __init__.py (located in the same folder)
from gym.envs.classic_control.myenv import MyEnv
Register the environment in gym/gym/envs/__init__.py by adding
gym.envs.register(
id='MyEnv-v0',
entry_point='gym.envs.classic_control:MyEnv',
max_episode_steps=1000,
)
At registration, you can also add reward_threshold and kwargs (if your class takes some arguments).
You can also directly register the environment in the script you will run (TRPO, PPO, or whatever) instead of doing it in gym/gym/envs/__init__.py.
EDIT
This is a minimal example to create the LQR environment.
Save the code below in lqr_env.py and place it in the classic_control folder of gym.
import gym
from gym import spaces
from gym.utils import seeding
import numpy as np
class LqrEnv(gym.Env):
def __init__(self, size, init_state, state_bound):
self.init_state = init_state
self.size = size
self.action_space = spaces.Box(low=-state_bound, high=state_bound, shape=(size,))
self.observation_space = spaces.Box(low=-state_bound, high=state_bound, shape=(size,))
self._seed()
def _seed(self, seed=None):
self.np_random, seed = seeding.np_random(seed)
return [seed]
def _step(self,u):
costs = np.sum(u**2) + np.sum(self.state**2)
self.state = np.clip(self.state + u, self.observation_space.low, self.observation_space.high)
return self._get_obs(), -costs, False, {}
def _reset(self):
high = self.init_state*np.ones((self.size,))
self.state = self.np_random.uniform(low=-high, high=high)
self.last_u = None
return self._get_obs()
def _get_obs(self):
return self.state
Add from gym.envs.classic_control.lqr_env import LqrEnv to __init__.py (also in classic_control).
In your script, when you create the environment, do
gym.envs.register(
id='Lqr-v0',
entry_point='gym.envs.classic_control:LqrEnv',
max_episode_steps=150,
kwargs={'size' : 1, 'init_state' : 10., 'state_bound' : np.inf},
)
env = gym.make('Lqr-v0')
Environment registration process can be found here.
Please go through this example custom environment if you have any more issues.
Refer to this stackoverflow issue for further information.
That problem is related to versions of gym try upgrading your gym environment.

Call up a function from another module

I am making a project where I need several modules which are imported into one main module. I have decided to move the interaction to a single Tkinter window. Instead of using input() I use tkinter.Entry(), for example. I have functions for each step of the interaction.
When I get past the last function of the first module, the configured button has a command to go to a function in the second module. I get an error saying that the command is not defined.
I seem unable to import the configured button variable into the next module, and anything else I tried gave no result. It simply doesn't go to the next module after the first module is done.
I have made the main Tkinter window in the main module and have it that it will mainloop after importing the other modules. Shouldn't the function I want to call upon be defined? How can I get from one function to the next if the latter is in a separate module?
Here is a minimal example:
main_script.py
import tkinter
mainwindow = tkinter.Tk()
# here i set the window to a certain size etc.
import mod1
import mod2
mainwindow.mainloop()
mod1.py
import tkinter
def button1():
label.destroy()
button1.destroy()
button2.config(text = "continue", command = func2)
def button2():
label.destroy()
button1.destroy()
button2.config(text = "continue", command = func2)
label = tkinter.Label(text = "example label")
button1 = tkinter.Button(text = "button1", command = button1)
button2 = tkinter.Button(text = "button2", command = button2)
label.pack()
button1.pack()
button2.pack()
mod2.py
def func2():
button2.destroy()
print ("haha it works...")
Importing a module has no effect on what the module you import can see. If you want to use mod1 contents in mod2 and mod2 contents in mod1, you need to have them import each other and refer to each other's contents with the appropriate module:
# mod1
import mod2
...
button2.config(text = "continue", command = mod2.func2)
# mod2
import mod1
def func2():
mod1.button2.destroy()
Circular imports cause nasty initialization order issues, though, so imports like this are a bad idea. When dividing your code into modules, try to do so in such a way that import loops like this aren't necessary.