Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
test/results/*
*.log
*.log
*.json
18 changes: 13 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
language: python
python:
- "2.7"
matrix:
include:
- python: "3.6"
env:
- INTERPRETER=python3
- python: "3.4"
env:
- INTERPRETER=python3

install:
- pip install robotframework
- pip install robotframework-selenium2library==1.8.0
- pip install robotframework==3.1.1
- pip install robotframework-seleniumlibrary==3.3.1
script:
- "python test/run_test.py"
- "$INTERPRETER --version"
- "$INTERPRETER test/run_test.py"
3 changes: 2 additions & 1 deletion Robot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Robot Framework from sublime is a autocompletion plugin for Sublime Text 3
Robot Framework Assistant offers IDE features for editing Robot Framework test
data in Sublime Text 3.
"""
import sys
import os
Expand Down
2 changes: 1 addition & 1 deletion Robot.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
and in Windows this could be like: C:\\Python27\\python.exe
*/

"path_to_python": "/usr/bin/python",
"path_to_python3": "/usr/bin/python",

/*
Module search path defines a list of paths where the
Expand Down
2 changes: 1 addition & 1 deletion command_helper/get_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,5 @@ def is_string(self, str_):
if version_info.major > 2:
status = isinstance(str_, str)
else:
status = isinstance(str_, basestring)
status = isinstance(str_, str)
return status
3 changes: 1 addition & 2 deletions command_helper/jump_to_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def get_library_path(self, imported_lib, open_tab, db_dir):
imported_file=imported_lib, open_tab=open_tab
)
else:
imported_lib_utf8 = imported_lib.encode('utf-8')
file_name = lib_table_name(imported_lib_utf8)
file_name = lib_table_name(imported_lib)
file_name = str(file_name)
file_path = os.path.join(db_dir, file_name)
data = get_data_from_json(file_path)
Expand Down
2 changes: 1 addition & 1 deletion command_helper/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_data_from_json(json_file):
def _keyword_with_embedded_arg(kw, kw_candite):
kw = kw.lower().replace(' ', '').replace('_', '')
kw_candite = kw_candite.lower().replace(' ', '').replace('_', '')
kw_re = re.sub(r'(?i)(\$\{[\w ]*\})', r'(?i)(\S+)', kw_candite)
kw_re = re.sub(r'(?i)(\$\{[\w ]*\})', r'(?i)(\\S+)', kw_candite)
return re.search(kw_re, kw)


Expand Down
2 changes: 1 addition & 1 deletion command_helper/workspace_objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import listdir, path
try:
from noralize_cell import get_data_from_json
from .noralize_cell import get_data_from_json
from db_json_settings import DBJsonSetting
except:
from ..command_helper.noralize_cell import get_data_from_json
Expand Down
1 change: 1 addition & 0 deletions commands/query_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def return_completions(self, view, prefix, locations):
# workspace = get_setting(SettingObject.workspace)
open_tab = view.file_name()
index_file = get_index_file(open_tab)
print(view, prefix, index_file)
if index_file:
return self.get_completions(view, prefix, index_file)
else:
Expand Down
1 change: 1 addition & 0 deletions commands/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def run_scan(self, log_file):
p_args = scan_popen_arg_parser('all')
p_args.append('--workspace')
p_args.append(get_setting(SettingObject.workspace))
print((" ".join(p_args)))
p = subprocess.Popen(
p_args,
stderr=subprocess.STDOUT,
Expand Down
4 changes: 2 additions & 2 deletions commands/scan_open_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def run_single_scan(self, open_tab, log_file):

def file_in_workspace(self, open_tab):
workspace = get_setting(SettingObject.workspace)
workspace = path.normcase(workspace)
open_tab = path.normcase(open_tab)
workspace = path.normpath(workspace)
open_tab = path.normpath(open_tab)
extension = get_setting(SettingObject.extension)
if open_tab.endswith(extension):
return open_tab.startswith(workspace)
Expand Down
68 changes: 44 additions & 24 deletions dataparser/data_parser/data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def parse_resource(self, file_path):
model = parsing.TestDataDirectory(source=folder).populate()
else:
model = parsing.ResourceFile(file_path).populate()
return self._parse_robot_data(file_path, model)
data = self._parse_robot_data(file_path, model)
data[DBJsonSetting.table_type] = DBJsonSetting.resource_file
return data
else:
logging.error('File %s could not be found', file_path)
raise ValueError(
Expand All @@ -56,7 +58,9 @@ def parse_suite(self, file_path):
self.file_path = file_path
if path.exists(file_path):
model = parsing.TestCaseFile(source=file_path).populate()
return self._parse_robot_data(file_path, model)
data = self._parse_robot_data(file_path, model)
data[DBJsonSetting.table_type] = DBJsonSetting.suite
return data
else:
logging.error('File %s could not be found', file_path)
raise ValueError(
Expand All @@ -78,6 +82,7 @@ def parse_variable_file(self, file_path, args=None):
for variable in variables:
var_list.append(variable[0])
data[DBJsonSetting.variables] = sorted(var_list)
data[DBJsonSetting.table_type] = DBJsonSetting.variable_file
return data

def parse_library(self, library, args=None):
Expand Down Expand Up @@ -116,6 +121,7 @@ def parse_library(self, library, args=None):
if data[DBJsonSetting.keywords] is None:
raise ValueError('Library did not contain keywords')
else:
data[DBJsonSetting.table_type] = DBJsonSetting.library
return data

def register_console_logger(self):
Expand All @@ -140,8 +146,10 @@ def _parse_python_lib(self, library, args):
else:
import_name = library
importer = Importer('test library')
lib_args = self._argument_strip(lib, args)
libcode = importer.import_class_or_module(
import_name, return_source=False)
import_name, instantiate_with_args=lib_args,
return_source=False)
kw_with_deco = self._get_keywords_with_robot_name(libcode)
for keyword in lib.keywords:
kw = {}
Expand All @@ -158,22 +166,36 @@ def _parse_python_lib(self, library, args):
kws[strip_and_lower(keyword.name)] = kw
return kws

def _get_keywords_with_robot_name(self, libcode):
def _argument_strip(self, lib, given_args):
formated_args = []
if not given_args:
return formated_args
try:
default_args = lib.inits[0].args
except IndexError:
default_args = []
for default_arg in default_args:
if '=' in default_arg:
default_parts = default_arg.split('=', 1)
formated_args.append(default_parts[1])
else:
formated_args.append(default_arg)
return formated_args

def _get_keywords_with_robot_name(self, lib_instance):
"""Returns keywords which uses Robot keyword decorator with robot_name

The keyword name can be chaned with Robot Framework keyword decorator
and by using the robot_name attribute. Return dictinionary which key is
the value of the robot_name attribute and the orinal function name.
The keyword name can be changed with Robot Framework keyword decorator
and by using the robot_name attribute. Return dictionary which key is
the value of the robot_name attribute and the original function name.
"""
kw_deco = {}
for key in libcode.__dict__:
if callable(libcode.__dict__[key]):
try:
if 'robot_name' in libcode.__dict__[key].__dict__:
kw = libcode.__dict__[key].__dict__['robot_name']
kw_deco[kw] = key
except AttributeError:
pass
lib_class = type(lib_instance)
for name in dir(lib_instance):
owner = lib_class if hasattr(lib_class, name) else lib_instance
method_attrib = getattr(owner, name)
if hasattr(method_attrib, 'robot_name') and method_attrib.robot_name:
kw_deco[method_attrib.robot_name] = name
return kw_deco

def _get_library_kw_source(self, libcode, keyword):
Expand All @@ -182,17 +204,15 @@ def _get_library_kw_source(self, libcode, keyword):
func_file = None
if hasattr(libcode, kw_func):
func = getattr(libcode, kw_func)
else:
func_file, func = None, None
if func:
kw_class = self.get_class_that_defined_method(func)
if kw_class:
func_file = self.get_function_file(kw_class)
else:
func_file = self.get_function_file(func)
return func.__code__.co_filename
return func_file

def get_class_that_defined_method(self, meth):
try:
class_mro = inspect.getmro(meth.im_class)
class_mro = inspect.getmro(meth.__self__.__class__)
except AttributeError:
return None
for cls in class_mro:
Expand Down Expand Up @@ -236,7 +256,7 @@ def _argument_path_formatter(self, library, args):

def _parse_xml_doc(self, library):
root = ET.parse(library).getroot()
if ('type', DBJsonSetting.library) in root.items():
if ('type', DBJsonSetting.library) in list(root.items()):
return root.attrib['name'], self._parse_xml_lib(root)
else:
raise ValueError('XML file is not library: {0}'.format(
Expand Down Expand Up @@ -323,8 +343,8 @@ def _format_resource(self, setting, file_path):
c_dir = path.dirname(self.file_path)
resource_path = normalise_path(path.join(c_dir, setting.name))
if not path.isfile(resource_path):
print ('Import failure on file: {0},'.format(file_path),
'could not locate: {0}'.format(setting.name))
print(('Import failure on file: {0},'.format(file_path),
'could not locate: {0}'.format(setting.name)))
return resource_path

def _format_variable_file(self, setting):
Expand Down
12 changes: 5 additions & 7 deletions dataparser/queue/scanner.py → dataparser/data_queue/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import os
import xml.etree.ElementTree as ET
from robot.errors import DataError
from finder import finder
from .finder import finder
from data_parser.data_parser import DataParser
from queue import ParsingQueue
from .queue import ParsingQueue
from parser_utils.file_formatter import rf_table_name, lib_table_name
from parser_utils.util import normalise_path
from db_json_settings import DBJsonSetting
Expand Down Expand Up @@ -40,11 +40,9 @@ def scan(self, workspace, ext, db_path):
if not os.path.dirname(workspace):
raise EnvironmentError(
'Workspace must be folder: {0}'.format(str(workspace)))
if not os.path.exists(db_path):
os.makedirs(db_path)
else:
if os.path.exists(db_path):
shutil.rmtree(db_path)
os.makedirs(db_path)
os.makedirs(db_path)
self.add_builtin()
if self.xml_libraries:
self.add_xml_libraries(self.xml_libraries)
Expand Down Expand Up @@ -146,7 +144,7 @@ def add_libraries_queue(self, libs):

def add_var_files_queue(self, var_files):
for var_file in var_files:
file_name = var_file.keys()[0]
file_name = list(var_file)[0]
self.queue.add(
file_name,
'variable_file',
Expand Down
8 changes: 4 additions & 4 deletions dataparser/index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from collections import namedtuple
from parser_utils.file_formatter import rf_table_name, lib_table_name
from parser_utils.util import get_index_name
from queue.queue import ParsingQueue
from data_queue.queue import ParsingQueue
from data_parser.data_parser import DataParser
from db_json_settings import DBJsonSetting
from queue.finder import finder
from data_queue.finder import finder

logging.basicConfig(
format='%(levelname)s:%(asctime)s: %(message)s',
Expand Down Expand Up @@ -175,7 +175,7 @@ def get_imports(self, data):
result += self.get_library_imports(data)
if DBJsonSetting.variable_files in data:
for var in data[DBJsonSetting.variable_files]:
result.append(rf_table_name(var.keys()[0]))
result.append(rf_table_name(list(var)[0]))
if DBJsonSetting.resources in data:
for resource in data[DBJsonSetting.resources]:
result.append(rf_table_name(resource))
Expand Down Expand Up @@ -221,7 +221,7 @@ def get_keywords(self, data):
arg_list = []
if DBJsonSetting.keywords in data:
kws = data[DBJsonSetting.keywords]
for kw in kws.iterkeys():
for kw in kws.keys():
kw_list.append(kws[kw][DBJsonSetting.keyword_name])
kw_args = self.get_kw_arguments(
kws[kw][DBJsonSetting.keyword_arguments])
Expand Down
8 changes: 5 additions & 3 deletions dataparser/parser_utils/file_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


def rf_table_name(f_path):
md5sum = md5(f_path.encode('utf-8')).hexdigest()
md5sum = md5(f_path.encode() if isinstance(f_path, str)
else f_path).hexdigest()
return '{realname}-{md5}.json'.format(
realname=path.basename(f_path)[-100:],
md5=md5sum
Expand All @@ -12,6 +13,7 @@ def rf_table_name(f_path):

def lib_table_name(library):
return '{realname}-{md5}.json'.format(
realname=library[-100:].decode('ascii'),
md5=md5(library).hexdigest()
realname=library[-100:],
md5=md5(library.encode() if isinstance(library, str)
else library).hexdigest()
)
4 changes: 2 additions & 2 deletions dataparser/parser_utils/util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from os import path

import glob

def normalise_path(f_path):
dirname = path.abspath(path.dirname(f_path))
basename = path.basename(f_path)
dirname = path.normpath(path.normcase(dirname))
dirname = path.normpath(dirname)
return path.join(dirname, basename)


Expand Down
2 changes: 1 addition & 1 deletion dataparser/run_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SETTING_DIR = path.join(ROOT_DIR, '..', 'setting')
sys.path.append(SETTING_DIR)

from queue.scanner import Scanner
from data_queue.scanner import Scanner


def scan_all(workspace, extension, db_path,
Expand Down
2 changes: 2 additions & 0 deletions messages/st3-6.3.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Drop PY2 support
Support new RBFW and SeleniumLibrary
3 changes: 3 additions & 0 deletions setting/db_json_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DBJsonSetting(object):
library_path = 'library_path'
resources = 'resources'
tags = 'tags'
table_type = 'table_type'
variable = 'variable'
variable_files = 'variable_files'
variables = 'variables'
Expand All @@ -31,3 +32,5 @@ class DBJsonSetting(object):
# Import setting types
variable_file = 'variable_file'
resource_file = 'resource_file'

suite = 'suite'
2 changes: 1 addition & 1 deletion setting/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SettingObject(object):
scanner_runner = 'scanner_runner'
index_runner = 'index_runner'
log_file = 'log_file'
python_binary = 'path_to_python'
python_binary = 'path_to_python3'
workspace = 'robot_framework_workspace'
extension = 'robot_framework_extension'
builtin_variables = 'robot_framework_builtin_variables'
Expand Down
Loading