Skip to content

Commit

Permalink
all tests passing. Ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
ronandrevon committed Oct 13, 2023
1 parent d176ffb commit fd23087
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 136 deletions.
14 changes: 12 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# Version log
## 0.0.7dev
## 0.0.8dev

## 0.0.7
### Fri 13 Oct 13:01:43 CEST 2023
- tests :
- test *solve_rock.py*
- fix pb `test_download` and `test_zenodo` when run with other tests
- added possibility to check the style of an element
- changed `elt.clear()` to execute_script as it would delete `input_rock_name`
- all tests passing with `--sleep=1`
- put short timers at some points but there are still failures when rocking on full speed mode
### Thu 12 Oct 18:30:11 CEST 2023
- tests:
- capturing browser console to the report folder *console.log*
- capturing browser console to the report folder *console.log*
### Thu 12 Oct 13:11:11 BST 2023
- issue#62 : delete frames
- simple new feature
Expand Down
1 change: 1 addition & 0 deletions static/js/bloch.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ angular.module('app')
}

$scope.save_rock=function(){
$log.log('saving rock')
if (!$scope.rock_names.includes($scope.rocks.name)){
$http.post('save_rock',JSON.stringify({'rock_name':$scope.rocks.name}))
.then(function(response){
Expand Down
2 changes: 1 addition & 1 deletion static/js/mainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ angular.module('app').
$scope.new_structure=function(){
$http.post('new_structure',JSON.stringify($scope.new_project))
.then(function(response){
$log.log('new_structure response : ',response.data);
// $log.log('new_structure response : ',response.data);
if(response.data.msg){
$scope.new_project.error = true;
$scope.show_error(response.data.msg,1)
Expand Down
2 changes: 1 addition & 1 deletion static/views/structure.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>

<div style="margin-left:5px;" ng-show="expand['struct']">
<div style="font-size:16px;margin:5px;">Cif file : <span ng-bind="crys['file']"/> </div>
<div style="font-size:16px;margin:5px;">Cif file : <span id="cif_file_div" ng-bind="crys['file']"/> </div>
<div style="font-size:16px;margin:5px;">Chemical formula : </div>
<div style="margin-left:30px;margin-top:-5px;">
<span id="formula" >$H_2O$</span>
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def sec(pytestconfig):
return sleep


# @pytest.fixture(scope="package")
# def port(pytestconfig):
# return pytestconfig.getoption('port')
@pytest.fixture(scope="package")
def port(pytestconfig):
return pytestconfig.getoption('port')

@pytest.fixture(scope="package")
def address(pytestconfig):
Expand Down
10 changes: 5 additions & 5 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function usage(){
- h : show this help
- H : headless mode (default False)
- s : seconds to sleep between widget manipulations
- l : marker lvl (default 2)
- l : marker lvl (default 3)
- A : any other arguments to pass to pytest
- m : run selected tests, see examples (if not specified runs all tests)
Note that login and close are added automatically
Expand Down Expand Up @@ -48,7 +48,7 @@ env_bin=$(realpath $dir/../.env/bin)
date=$(date "+%y_%m_%d-%H_%M")

args=
lvl=2
lvl=3
address=
do_report=0
do_coverage=0
Expand All @@ -75,7 +75,7 @@ while getopts ":l:a:A:p:s:m:rdHReCh" arg; do
markers="login $OPTARG close" #;echo "$markers"
;;
A)
args=" "$OPTARG" "
args+=" "$OPTARG" "
;;
i)
report_dir='report_custom'
Expand Down Expand Up @@ -125,12 +125,12 @@ if [ $do_report -eq 1 ];then
server_log="$report_dir/server.log"
console_log="$report_dir/console.log"
args+=" --report=$console_log "

cd $dir/..
echo 'Launching server for reporting' >> "tests/$report_log"; tail -n1 "tests/$report_log"
$env_bin/python3 serve.py -p $port &> "tests/$server_log" &
server_pid=$!
html="--html=$dir/$report_dir/report.html --self-contained-html"
html="--html=$dir/$report_dir/report.html --self-contained-html --capture sys -rP -rF"
cd $dir

##check the port is correct
Expand Down
142 changes: 134 additions & 8 deletions tests/selenium_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from utils import glob_colors as colors
from subprocess import check_output
from time import sleep

d = datetime.datetime.today()
str_date = d.strftime("%d-%m-%y_%H-%M-%S")
struct_test='bot_test_%s' %str_date
# struct_test='new_test'
dat_folder=os.path.realpath(os.path.join(os.path.dirname(__file__),
'../static/spg/'))
rock_name='test_5'
rock_name='test_3pts'
frame='frames_test'
cif_file = 'alpha_glycine.cif'
cif_path = os.path.join(dat_folder,cif_file)
Expand All @@ -21,6 +24,19 @@
}
# fails=['fail_pets.zip','fail_dials.zip']

def remove_data_folder(data_folder):
''' delete folder and reload the page'''
folder_path='../static/database/%s' %data_folder
if os.path.exists(folder_path):
cmd="rm -rf %s" %folder_path
check_output(cmd,shell=True)
return os.path.exists(folder_path)

################################################################################
################################################################################
#### widget interaction
################################################################################
################################################################################
def click(d,id,sec,exec=True):
elt = WebDriverWait(d, timeout=3).until(lambda d:d.find_element("id", id))
if exec:
Expand All @@ -37,18 +53,37 @@ def focus(d,id,sec):
def clear(d,id):
elt = WebDriverWait(d, timeout=3).until(lambda d:d.find_element("id", id))
elt.clear()
def write(d,id,s,sec,clear=False):
def write(d,id,s,sec,clear=False,exec=False):
elt = WebDriverWait(d, timeout=3).until(lambda d:d.find_element("id", id))
# d.execute_script("arguments[0].value='%s';" %s, elt)
if clear:
elt.clear()
elt.send_keys(s)
if exec:
# elt.click()
d.execute_script("arguments[0].value='%s';" %s, elt)
else:
if clear:
d.execute_script("arguments[0].value='';", elt)
#### Note : for some reason there are input for which elt.clear()
#### results in the element being removed
# elt.clear()
elt.send_keys(s)
sleep(sec)

def check_text(d,id,s):
WebDriverWait(d, timeout=3).until(lambda d:d.find_element("id", id).text==s)
try:
WebDriverWait(d, timeout=3).until(lambda d:d.find_element("id", id).text==s)
except Exception as e:
if d.find_element("id", id).is_displayed():
print('\n')
print('expected text :%s' %s)
print('actual text : %s' %d.find_element("id", id).text)
raise Exception(e)

def get_elt_txt(d,id):
return d.find_element("id", id).text
def get_elt(d,id):
return d.find_element("id", id)

def print_text(d,id):
print(d.find_element("id", id).text)
print(get_elt_txt(d,id))

def check_plotly_elt_text(d,id,classname,s):
# print(d.find_element('id',id).find_element("class name", classname).text)
Expand All @@ -64,3 +99,94 @@ def select_by_text(d,id,text,sec):
select=Select(d.find_element('id',id))
select.select_by_visible_text(text)
sleep(sec)

def get_elt_style(d,id):
# elt = d.find_element("id", id)
return dictify_style(get_elt(d,id).get_attribute("style"))

def dictify_style(style_str):
style=style_str.strip().split(";")[:-1]
style_dict={item[0].strip(): item[1].strip() for item in
map(lambda s: s.split(":"), style)}
return style_dict

def check_prop_val(d,id,prop,val):
style=get_elt_style(d,id)
if prop in style.keys():
# print(style_dict)
return style[prop]==val
else:
return False

def check_elt_style(d,id,prop,val):
try:
WebDriverWait(d, timeout=3).until(lambda d:check_prop_val(d,id,prop,val))
except Exception as e:
if d.find_element("id", id).is_displayed():
print('\n')
print('expected style value :%s' %val)
print('actual text : %s' %get_elt_style(d,id)[prop])
raise Exception(e)


################################################################################
################################################################################
#### utils
################################################################################
################################################################################
def select_frames(chrome_driver,sec):
if not chrome_driver.find_element("id", "import_menu_open_btn").is_displayed():
click(chrome_driver,'expand_import_menu',sec)
click(chrome_driver,'import_menu_frames_btn',sec)


def import_cif(chrome_driver,sec):
if not chrome_driver.find_element("id", "import_menu_open_btn").is_displayed():
click(chrome_driver,'expand_import_menu',sec)

print(colors.green+"\nImport cif "+colors.yellow+cif_path+colors.black,end="")
click(chrome_driver,'import_menu_cif_btn',sec)
write(chrome_driver,'input_Cif_file',cif_path,sec)
click(chrome_driver,'import_cif_file_button',sec)

print(colors.green+",Check import"+colors.black,end="")
check_text(chrome_driver,'current_cif_file_div',cif_file)
click(chrome_driver,'import_menu_open_btn',sec)
click(chrome_driver,'info_struct_refresh_btn',sec)
check_text(chrome_driver,'info_struct_cif',cif_file)

print(colors.green+"done"+colors.black)
click(chrome_driver,'expand_import_menu',sec)

def check_cif(chrome_driver,sec):
if not chrome_driver.find_element("id", "cif_file_div").is_displayed():
click(chrome_driver,'expand_structure_panel',sec)
cif_file=get_elt_txt(chrome_driver,"cif_file_div")#;print("'%s'" %cif_file)
if cif_file=='?':
import_cif(chrome_driver,sec)
click(chrome_driver,'expand_structure_panel',sec)


def import_dat(chrome_driver,sec):
if not chrome_driver.find_element("id", "import_menu_open_btn").is_displayed():
click(chrome_driver,'expand_import_menu',sec)
print(colors.green+"\nImport dat"+colors.black,end="")
click(chrome_driver,'import_menu_dat_btn',sec)

for dat_type,dat_file in dat_files.items():
print(', '+colors.yellow+dat_type+colors.green,end="")
dat_path = os.path.join(dat_folder,dat_file)
write(chrome_driver,'input_dat_file',dat_path,sec)
check_text(chrome_driver,'dat_type_span',dat_type)
click(chrome_driver,'import_dat_file_btn',sec)


dat_type='xds'
print(colors.green+", select and check " +colors.yellow+dat_type+colors.black,end="")
select_by_text(chrome_driver,'dat_type_select',dat_type,sec)
click(chrome_driver,'import_menu_open_btn',sec)
click(chrome_driver,'info_struct_refresh_btn',sec)
check_text(chrome_driver,'info_struct_dat',dat_type)

print(colors.green+", done"+colors.black)
click(chrome_driver,'expand_import_menu',sec)
69 changes: 12 additions & 57 deletions tests/test_bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,36 @@
from selenium.webdriver.common.keys import Keys
from selenium_utils import*

@pytest.mark.lvl1
def test_import_cif(chrome_driver,sec):
if not chrome_driver.find_element("id", "import_menu_open_btn").is_displayed():
click(chrome_driver,'expand_import_menu',sec)

print(colors.green+"\nImport cif "+colors.yellow+cif_path+colors.black,end="")
click(chrome_driver,'import_menu_cif_btn',sec)
write(chrome_driver,'input_Cif_file',cif_path,sec)
click(chrome_driver,'import_cif_file_button',sec)

print(colors.green+",Check import"+colors.black,end="")
check_text(chrome_driver,'current_cif_file_div',cif_file)
click(chrome_driver,'import_menu_open_btn',sec)
click(chrome_driver,'info_struct_refresh_btn',sec)
check_text(chrome_driver,'info_struct_cif',cif_file)

print(colors.green+"done"+colors.black)
click(chrome_driver,'expand_import_menu',sec)


@pytest.mark.lvl2
def test_import_dat(chrome_driver,sec):
if not chrome_driver.find_element("id", "import_menu_open_btn").is_displayed():
click(chrome_driver,'expand_import_menu',sec)
print(colors.green+"\nImport dat"+colors.black,end="")
click(chrome_driver,'import_menu_dat_btn',sec)

for dat_type,dat_file in dat_files.items():
print(', '+colors.yellow+dat_type+colors.green,end="")
dat_path = os.path.join(dat_folder,dat_file)
write(chrome_driver,'input_dat_file',dat_path,sec)
check_text(chrome_driver,'dat_type_span',dat_type)
click(chrome_driver,'import_dat_file_btn',sec)


dat_type='xds'
print(colors.green+", select and check " +colors.yellow+dat_type+colors.black,end="")
select_by_text(chrome_driver,'dat_type_select',dat_type,sec)
click(chrome_driver,'import_menu_open_btn',sec)
click(chrome_driver,'info_struct_refresh_btn',sec)
check_text(chrome_driver,'info_struct_dat',dat_type)

print(colors.green+", done"+colors.black)
click(chrome_driver,'expand_import_menu',sec)



@pytest.mark.lvl1
def test_bloch_mode(chrome_driver,sec):
print(colors.green+"\nTesting bloch mode"+colors.black,end="")
click(chrome_driver,'bloch_tab',sec)
check_text(chrome_driver,'mode_title_panel','Bloch solver')

@pytest.mark.lvl1
def test_bloch_single(chrome_driver,sec):
print(colors.green+"\nTesting bloch single mode"+colors.black,end="")
print(colors.blue+", check cif"+colors.black,end="")
check_cif(chrome_driver,sec)

print(colors.blue+", bloch single "+colors.black,end="")
click(chrome_driver,'bloch_tab',sec)
check_text(chrome_driver,'mode_title_panel','Bloch solver')
click(chrome_driver,'u_single',sec)
click(chrome_driver,'u_edit',sec)
write(chrome_driver,'u_input','0.1,0.2,1',sec,clear=True)

print(colors.blue+", solve"+colors.black,end="")
sleep(0.2)
click(chrome_driver,'solve_btn',2)
check_text(chrome_driver,'solve_btn','Completed')

@pytest.mark.lvl2
def test_bloch_thick(chrome_driver,sec):
print(colors.blue+", thick"+colors.black,end="")
thick=550
if not chrome_driver.find_element("id", "bloch_thick_input").is_displayed():
click(chrome_driver,'expand_bloch_thick_panel',sec)

write(chrome_driver,'bloch_thick_input',str(thick),sec,clear=True)
write(chrome_driver,'bloch_thick_input',Keys.ENTER,sec)
check_plotly_elt_text(chrome_driver,'fig1','gtitle','diffraction pattern z=%d A' %thick)

#navigate thickness
# print(colors.blue+", nav thick"+colors.black,end="")
# click(chrome_driver,'bloch_thick_btn',sec)


print(colors.blue+", thicks"+colors.black,end="")
thicks=str((100,550,100))
write(chrome_driver,'bloch_thicks_input',str(thicks),sec,clear=True)
Expand Down
Loading

0 comments on commit fd23087

Please sign in to comment.