Yoda

This section contains source code documentation of Yoda extension.

yoda

Providing automated testing functionality

class hydratk.extensions.yoda.yoda.Extension(core_instance=None)

Class Extension

_init_extension()

Method initializes extension

Parameters:none
Returns:void
_check_dependencies()

Method checks dependent modules

Parameters:none
Returns:bool
_uninstall()

Method returns additional uninstall data

Parameters:none
Returns:list (files), list (modules)
Return type:tuple
_init_repos()

Method initializes test repositories

Configuration option Extensions/Yoda/test_repo_root lib - low level auxiliary test methods helpers - high level auxiliary test methods yoda-tests - test scripts

Parameters:none
Returns:void
_update_repos()

Method updates test repositories

Parameters:none
Returns:void
_register_actions()

Method registers event hooks

Parameters:none
Returns:void
check_pp_mode(ev)

Method registers event hooks for parallel processing

Parameters:none
Returns:void
_register_htk_actions()

Method registers command hooks

Parameters:none
Returns:void
_register_standalone_actions()

Method registers command hooks for standalone mode

Parameters:none
Returns:void
pp_app_check(ev)

Method ensures test run completion when all parallel execution are completed

Parameters:

ev (obj) – not used

Returns:

void

Raises:
  • exception – Exception
  • event – yoda_before_check_results
create_test_results_db()

Method creates results database

Parameters:none
Returns:database
Return type:obj
create_testdata_db()

Method creates testdata database

Database dsn is read from command option yoda-db-testdata-dsn or configuration Database can be rewritten by command option force

Parameters:none
Returns:bool
init_check(ev)

Event listener waiting for htk_on_cmd_options event

If there’s –yoda-test-repo-root-dir parameter presence, it will try to override current settings
Parameters:ev (object) – hydratk.core.event.Event
Returns:void
init_test_simul()

Method enables simulated execution

Parameters:none
Returns:void
init_test_results_db()

Method initialized results database

Configuration option - Yoda/db_results_dsn

Parameters:none
Returns:void
Raises:exception – Exception
check_test_results_db(ev)

Method check if results database is successfully created

Configuration option - Yoda/db_results_autocreate It is created if autocreate enabled

Parameters:ev – not used
Returns:void
Raises:exception – Exception
init_tests()

Method is initializing tests

Parameters:

none

Returns:

void

Raises:
  • event – yoda_before_init_tests
  • event – yoda_before_process_tests
  • event – yoda_before_check_results
init_helpers()

Method initializes helpers repository

Parameters:none
Returns:void
Raises:event – yoda_before_append_helpers_dir
init_libs()

Method initializes libraries repository

Parameters:none
Returns:void
Raises:event – yoda_before_append_lib_dir
process_tests(test_files, test_file_id)

Method determines whether test sets will be executed in single or parallel mode

Parameters:

test_files (obj) – list or str, test files

Returns:

void

Raises:
  • exception – Exception
  • event – yoda_before_parse_test_file
pp_process_test_set(test_set_file, test_set_file_id)

Method creates ticket to execute test set in parallel mode

Parameters:test_set_file (str) – filename
Returns:void
pp_run_test_set(test_set_file, test_set_file_id)

Method executes test set in parallel mode

Parameters:test_set_file (str) – filename
Returns:void
Raises:exception – Exception
process_test_set(test_set_file, test_set_file_id)

Method executes test set in single mode

Parameters:test_set_file (str) – filename
Returns:void
Raises:exception – Exception
_check_results()

Method prepares results in requested format

Parameters:none
Returns:void
Raises:event – yoda_on_check_results

bootstrapper

Providing custom bootstrapper for yoda standalone app

hydratk.extensions.yoda.bootstrapper.run_app()

Methods runs yoda standalone application

Parameters:none
Returns:void

testengine

Providing automated testing functionality

class hydratk.extensions.yoda.testengine.This(map_obj=None)

Class This

__init__(map_obj=None)

Class constructor

Called when object is initialized

Parameters:map_obj (obj) – test object
__setattr__(name, value)

Method sets attribute

Parameters:
  • name (str) – attribute name
  • value (obj) – attribute value
Returns:

void

__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
Raises:error – AttributeError
__weakref__

list of weak references to the object (if defined)

class hydratk.extensions.yoda.testengine.Current

Class Current

te

te property getter, setter

test_set

test_set property getter, setter

tset

tset property getter, setter

test_scenario

test_scenarion property getter

ts

ts property getter, setter

test_case

test_case property getter

tca

tca property getter, setter

test_condition

test_condition property getter

tco

tco property getter, setter

__weakref__

list of weak references to the object (if defined)

class hydratk.extensions.yoda.testengine.Parent

Class Parent

test_set

test_property getter, setter

tset

tset property getter, setter

test_scenario

test_scenarion property getter

ts

ts property getter, setter

test_case

test_case property getter

tca

tca property getter, setter

__weakref__

list of weak references to the object (if defined)

class hydratk.extensions.yoda.testengine.TestSet(current, test_set_file, test_set_file_id)

Class TestSet

append_ts(ts_obj)

Method adds new scenario to test set

Parameters:ts_obj (obj) – test scenario
Returns:void
class hydratk.extensions.yoda.testengine.TestScenario(ts_num, parent_tset, current)

Class TestScenario

repeat()

Method enables scenario to be repeated

Parameters:none
Returns:void
append_tca(tca)

Method adds new test case to test scenario

Parameters:tca (obj) – test case
Returns:void
class hydratk.extensions.yoda.testengine.TestCase(tca_num, parent_ts, current)

Class TestCase

repeat()

Method enables case to be repeated

Parameters:none
Returns:void
append_tco(tco)

Method adds new test condition to test case

Parameters:tco (obj) – test condition
Returns:void
class hydratk.extensions.yoda.testengine.TestCondition(tco_num, parent_tca, current)

Class TestCondition

repeat()

Method enables condition to be repeated

Parameters:none
Returns:void
class hydratk.extensions.yoda.testengine.MacroParser(regexp=None)

Class MacroParser

mp_add_hooks(*args, **kwargs)

Method registers macro hooks

Macro is identified by name and contains callback

Parameters:
  • args (args) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

void

mp_add_hook(name, cb)

Method registers macro hook

Parameters:
Returns:

void

mp_parse(content)

Method parses macro string

Parameters:content (str) – macro string
Returns:regexp group
Return type:obj
_mp_processor(match)

Method executes macro

Parameters:match (obj) – regexp group
Returns:callback result str: when macro is not defined
Return type:obj
__weakref__

list of weak references to the object (if defined)

class hydratk.extensions.yoda.testengine.TestEngine

Class TestEngine

code_stack

code_stack property getter

test_repo_root

test_repo_root property getter, setter

libs_repo

libs_repo prooperty getter, setter

templates_repo

templates_repo property getter, setter

have_test_results_db

have_test_results_db property getter

test_results_db

test_results_db property getter, setter

helpers_repo

helpers_repo property getter, setter

get_ts_filter(index_file)

Method gets test scenario filter

Parameters:index_file (str) – file index
Returns:dict
get_tca_filter(index_file)

Method gets test case filter

Parameters:index_file (str) – file index
Returns:dict
get_tco_filter(index_file)

Method get test condition filter

Parameters:index_file (str) – file index
Returns:dict
run_mode_area

run_mode_area property getter, setter

run_mode_src

run_mode_src property getter, setter

exec_level

exec_level property getter

test_simul_mode

test_simul_mode property getter, setter

test_run

test_run property getter, setter

__init__()

Class constructor

Called when object is initialized

Parameters:none
new_test_run()

Method creates new test run

Parameters:none
Returns:void
_h_include(content_file)

Method loads content of included file

Parameters:content_file (str) – filename including path
Returns:content
Return type:str
load_tset_from_file(tset_file)

Method loads test content from file

Parameters:tset_file (str) – filename including path
Returns:test set when loaded bool: False otherwise
Return type:dict
load_tset_from_str(tset_str, origin_file=False)

Method loads test set content from string

Parameters:
  • tset_str (str) – test set content
  • origin_file (bool) – string loaded from file
Returns:

test set when loaded bool: False otherwise

Return type:

dict

_parse_ts_node(ts_node, ts)

Method parses test scenario

Parameters:
  • ts_node (dict) – test scenario node
  • ts (obj) – test scenario object
Returns:

void

_parse_tca_node(tca_node, tca)

Method parses test case

Parameters:
  • tca_node (dict) – test case node
  • tca (obj) – test case object
Returns:

void

_parse_tco_node(tco_node, tco)

Method parses test condition

Parameters:
  • tco_node (dict) – test condition node
  • tco (obj) – test condition object
Returns:

void

parse_tset_struct(tset_struct, tset_id, exec_mode=1, report_results=1)

Method parses test set

Hierarchy test scenario, case, condition

Parameters:
  • tset_struct (dict) – test set structure
  • tset_id (str) – test set id
  • exec_mode (int) – mode regarding current test set execution, 1 (default) - native, 2 - inline
  • report_results (int) – 1 (default) results reported, 0 results not reported
Returns:

test set

Return type:

obj

exec_test(test_path, report_results=1)

Method executes tests in path

Parameters:
  • test_path (str) – test path
  • report_results (int) – 1 (default) results reported, 0 results not reported
Returns:

result – {

‘total_tests’ : int, ‘passed_tests’ : int, ‘failed_tests’ : int, ‘detail’ : {

test_set_id : {

‘total_tests’ : int, ‘passed_tests’ : int, ‘failed_tests’ : int,

}

}

}

Return type:

dict

Raises:
  • exception – Exception
  • event – yoda_before_parse_test_file
get_all_tests_from_container(container_file)

Method returns all tests found in container

Parameters:container_file (str) – filename including path
Returns:tests
Return type:list
get_all_tests_from_path(test_path)

Method returns all found test in path

Test files are filtered by .jedi file extension
Parameters:test_path (str) – test path
Returns:test_files (list), test_id (list)
Return type:tuple
Raises:event – yoda_before_append_test_file
class hydratk.extensions.yoda.testengine.CodeStack

Class CodeStack

testobject

Providing automated testing functionality

class hydratk.extensions.yoda.testobject.TestObject

Class TestObject

parent

parent property getter

exec_mode

exec_mode property getter

report_results

report_results property getter

cprint(content)

Method prints content regarding the report_results option

Parameters:content (mixed) – content
Returns:void
exec_test(test_path, report_results=1)

Method executes tests in path, wrapper for using in tests

Parameters:
  • test_path (str) – test path
  • report_results (int) – 1 (default) results reported, 0 results not reported
Returns:

result – {

‘total_tests’ : int, ‘passed_tests’ : int, ‘failed_tests’ : int, ‘detail’ : {

test_set_id : {

‘total_tests’ : int, ‘passed_tests’ : int, ‘failed_tests’ : int,

}

}

}

Return type:

dict

write_custom_data()

Method writes test scenario custom data to results database

Data can be filtered

Parameters:none
Returns:void
setattr_opt(attr_key, opt_name, opt_value=None)

Method sets attribute option

Parameters:
  • attr_key (str) – attribute key name
  • opt (obj) – option name
  • opt_value (mixed) – option value
Returns:

True on success

Return type:

bool

Raises:
  • error – ValuError
  • error – KeyError
getattr_opt(attr_key, opt)

Method gets attribute option

Parameters:
  • attr_key (str) – attribute key name
  • opt (str) – option name
Returns:

attribute value

Return type:

obj

Raises:
  • error – ValuError
  • error – KeyError
getattr(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
setattr(key, val, options=None)

Method sets attribute

Parameters:
  • key (str) – attribute name
  • val (obj) – attribute value
  • (dict) attribute options (options) –
Returns:

void

__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
get_auto_break()

Method gets auto_break from configuration Yoda/auto_break

Parameters:none
Returns:configured auto_break
Return type:str
_explain(exc_name, exc_value, test_hierarchy, tb)

Method describes exception occurence within test execution

Parameters:
  • exc_name (str) – exception name
  • exc_value (str) – exception value
  • test_hierarchy (dict) – test hierarchy set -> scenario -> case -> condition
  • tb (obj) – traceback
Returns:

description

Return type:

str

attr

attr property getter

attr_opt

attr_opt property getter

log

log property getter, setter

struct_log

struct_log property getter

__weakref__

list of weak references to the object (if defined)

exception hydratk.extensions.yoda.testobject.BreakTestRun

Class BreakTestRun

__weakref__

list of weak references to the object (if defined)

exception hydratk.extensions.yoda.testobject.BreakTest

Class BreakTest

test_object

test_object property getter, setter

__weakref__

list of weak references to the object (if defined)

exception hydratk.extensions.yoda.testobject.BreakTestCase

Class BreakTestCase

test_object

test_object property getter, setter

__weakref__

list of weak references to the object (if defined)

exception hydratk.extensions.yoda.testobject.BreakTestScenario

Class BreakTestScenario

test_object

test_object property getter, setter

__weakref__

list of weak references to the object (if defined)

exception hydratk.extensions.yoda.testobject.BreakTestSet

Class BreakTestSet

test_object

test_object property getter, setter

__weakref__

list of weak references to the object (if defined)

class hydratk.extensions.yoda.testobject.TestRun(test_engine=None)

Class TestRun

__init__(test_engine=None)

Class constructor

Called when object is initialized

Parameters:test_engine (obj) – test engine
create_db_record()

Method creates new record in results database

Parameters:none
Returns:void
update_db_record()

Method updates record in results database

Parameters:none
Returns:void
te

te property getter, setter

inline_tests

inline_tests property getter

id

id property getter

name

name property getter, setter

total_test_sets

total_test_sets property getter, setter

total_tests

total_tests property getter, setter

failed_tests

failed_tests property getter, setter

passed_tests

passed_tests property getter, setter

skipped_tests

skipped_tests property getter, setter

norun_tests

norun_tests property getter, setter

run_tests

run_tests property getter, setter

failures

failures property getter, setter

status

status property getter, setter

start_time

start_time property getter, setter

end_time

end_time property getter, setter

tset

tset property getter, setter

__repr__()

Method overrides __repr__

Parameters:none
Returns:str
break_test_run(reason)

Method breaks whole test run

Parameters:reason (str) – reason of break
Returns:void
Raises:exception – BreakTestRun
class hydratk.extensions.yoda.testobject.TestSet(current, test_set_file, test_set_file_id)

Class TestSet

id

id property getter

test_run

test_run property getter, setter

current_test_base_path

current_test_base_path property getter, setter

current_test_set_file

current_test_set_file property getter, setter

current_test_set_file_id

test_set_file_id property getter, setter

parsed_tests

parsed_tests property getter, setter

total_tests

total_tests property getter, setter

failed_tests

failed_tests property getter, setter

passed_tests

passed_tests property getter, setter

failed_ts

failed_ts property getter, setter

passed_ts

passed_ts property getter, setter

failures

failures property getter, setter

ts

ts property getter, setter

start_time

start_time property getter, setter

end_time

end_time property getter, setter

__init__(current, test_set_file, test_set_file_id)

Class constructor

Called when object is initialized

Parameters:
  • current (obj) – current test object
  • test_set_file (str) – filename with test set content
create_db_record()

Method creates new record in results database

Parameters:none
Returns:void
update_db_record()

Method updates record in results database

Parameters:none
Returns:void
__repr__()

Method overrides __repr__

Parameters:none
Returns:str
append_ts(ts)

Method adds new scenario to test set

Parameters:ts (obj) – test scenario
Returns:void
reset_data()

Method resets test set attributes

Parameters:none
Returns:void
run()

Method runs test set (test scenarios within)

Execution progress is stored in results database Test run and test can be broken during execution

Parameters:none
Returns:void
Raises:exception – Exception
break_test_set(reason, test_object=None)

Method breaks test set

Parameters:
  • reason (str) – reason of break
  • test_object (obj) – test object
Returns:

void

Raises:

exception – BreakTestSet

class hydratk.extensions.yoda.testobject.TestScenario(ts_num, parent_tset, current)

Class TestScenario

__init__(ts_num, parent_tset, current)

Class constructor

Called when object is initialized

Parameters:
  • ts_num (int) – test scenario number
  • parent_test_set (obj) – parent test set
  • current (obj) – current test object
obj_id

obj_id property getter

id

id property getter

num

num property getter

create_db_record()

Method creates new record in results database

Data can be filtered

Parameters:none
Returns:void
update_db_record()

Method updates record in results database

Data can be filtered

Parameters:none
Returns:void
run()

Method runs test scenario (test cases within)

Execution progress is stored in results database Test run, set, scenarion can be broken during execution

Parameters:

none

Returns:

True

Return type:

bool

Raises:
  • exception – Exception
  • event – yoda_before_exec_ts_prereq
  • event – yoda_events_before_start_ts
  • event – yoda_events_after_finish_ts
  • event – yoda_before_exec_ts_postreq
tca

tca property getter

resolution

resolution property getter, setter

status

status property getter, setter

prereq_passed

prereq_passed property getter, setter

postreq_passed

postreq_passed property getter, setter

events_passed

events_passed property getter, setter

failures

failures property getter, setter

action

action property getter, setter

total_tests

total_tests property getter, setter

passed_tests

passed_tests property getter, setter

failed_tests

failed_tests property getter, setter

start_time

start_time property getter, setter

end_time

end_time property getter, setter

break_test_scenario(reason)

Method breaks test scenario

Parameters:reason (str) – reason of break
Returns:void
Raises:exception – BreakTestScenario
break_test_set(reason)

Method breaks test set

Parameters:reason (str) – reason of break
Returns:void
break_test_run(reason)

Method breaks test run

Parameters:reason (str) – reason of break
Returns:void
class hydratk.extensions.yoda.testobject.TestCase(tca_num, parent_ts, current)

Class TestCase

__init__(tca_num, parent_ts, current)

Class constructor

Called when object is initialized

Parameters:
  • tca_num (int) – test case number
  • parent_ts (obj) – parent test set
obj_id

obj_id property getter

id

id property getter

num

num property getter

create_db_record()

Method creates new record in results database

Parameters:none
Returns:void
update_db_record()

Method updates record in results database

Parameters:none
Returns:void
run()

Method runs test case (test conditions within)

Execution progress is stored in results database Test run, set, scenario, case can be broken during execution

Parameters:

none

Returns:

True

Return type:

bool

Raises:
  • exception – Exception
  • event – yoda_events_before_start_tca
  • event – yoda_events_after_finish_tca
tco

tco property getter

resolution

resolution property getter, setter

status

status property getter, setter

failures

failures property getter, setter

tco_failures

tco_failures property getter, setter

action

action property getter, setter

total_tests

total_tests property getter, setter

passed_tests

passed_tests property getter, setter

failed_tests

failed_tests property getter, setter

failed_tco

failed_tco property getter, setter

passed_tco

passed_tco property getter, setter

start_time

start_time property getter, setter

end_time

end_time property getter, setter

events_passed

events_passed property getter, setter

break_test_case(reason)

Method breaks test case

Parameters:reason (str) – reason of break
Returns:void
Raises:exception – BreakTestCase
break_test_set(reason)

Method breaks test set

Parameters:reason (str) – reason of break
Returns:void
break_test_run(reason)

Method breaks test run

Parameters:reason (str) – reason of break
Returns:void
class hydratk.extensions.yoda.testobject.TestCondition(tco_num, parent_tca, current)

Class TestCondition

__init__(tco_num, parent_tca, current)

Class constructor

Called when object is initialized

Parameters:
  • tco_num (int) – test condition number
  • parent_tca (obj) – parent test case
  • current (obj) – current test object
id

id property getter

create_db_record()

Method creates new record in results database

Parameters:none
Returns:void
update_db_record()

Method updates record in results database

Parameters:none
Returns:void
run()

Method runs test condition

Execution progress is stored in results database Test run, set, scenario, case, condition can be broken during execution

Parameters:

none

Returns:

True

Return type:

bool

Raises:
  • exception – Exception
  • event – yoda_events_before_start_tco
  • event – yoda_before_exec_tco_test
  • event – yoda_before_exec_validate_test
  • event – yoda_events_after_finish_tco
resolution

resolution property getter, setter

status

status property getter, setter

failures

failures property getter, setter

action

action property getter, setter

expected_result

expected_result property getter, setter

test_resolution

test_resolution property getter, setter

test_result

test_result property getter, setter

test_output

test_output property getter, setter

test_assert

test_assert property getter, setter

test_validate

test_validate property getter, setter

start_time

start_time property getter, setter

end_time

end_time property getter, setter

events_passed

events_passed property getter, setter

test_exec_passed

test_exec_passed property getter, setter

validate_exec_passed

validate_exec_passed property getter, setter

break_test(reason)

Method breaks test condition

Parameters:reason (str) – reason of break
Returns:void
Raises:exception – BreakTest
break_test_case(reason)

Method breaks test case

Parameters:reason (str) – reason of break
Returns:void
break_test_scenario(reason)

Method breaks test scenario

Parameters:reason (str) – reason of break
Returns:void
break_test_set(reason)

Method breaks test set

Parameters:reason (str) – reason of break
Returns:void
break_test_run(reason)

Method breaks test run

Parameters:reason (str) – reason of break
Returns:void

testresults

  • testresults

Providing manipulation with test results

class hydratk.extensions.yoda.testresults.testresults.TestResultsDB(dsn)

Class TestResultsDB

trdb

trdb property getter

custom_data_filter

custom_data_filter property getter

__init__(dsn)

Class constructor

Called when object is initialized

Parameters:dsn (str) – dsn
db_check_ok()

Method checks if database is successfully created

Parameters:none
Returns:result
Return type:bool
create_database(force=False)

Method creates database

Parameters:force (bool) – recreate database if exists
Returns:void
Raises:exception – Exception
db_action(action, columns)

Method executes write query

Parameters:
  • action (str) – query
  • columns (dict) – binded columns
Returns:

void

db_data(action, columns)

Method executes read query

Parameters:
  • action (str) – query
  • columns (list) – returned columns
Returns:

query result

Return type:

dict

__weakref__

list of weak references to the object (if defined)

class hydratk.extensions.yoda.testresults.testresults.TestResultsOutputFactory(db_dsn, handler_def='console')

Class TestResultsOutputFactory

__init__(db_dsn, handler_def='console')

Class constructor

Called when object is initiazed

Parameters:
  • db_dsn (str) – dsn
  • handler_def (str) – output handler, console|html|text
__weakref__

list of weak references to the object (if defined)

_dispatch_handler_def(handler_def)

Method parses handler definition

Parameters:handler_def (str) – handler definition
Returns:void
Raises:error – TypeError
__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
__getitem__(name)

Method gets item

Parameters:name (str) – item name
Returns:item value
Return type:obj
_import_tro_handler(handler_name)

Method imports output handler

Parameters:handler_name (str) – handler
Returns:module
Return type:obj
  • console

Default test results console output handler

class hydratk.extensions.yoda.testresults.handlers.console.TestResultsOutputHandler(db_dsn, options={})

Class TestResultsOutputHandler

__init__(db_dsn, options={})

Class constructor

Called when object is initialized

Parameters:
  • db_dsn (str) – dsn
  • options (dict) – output options
__weakref__

list of weak references to the object (if defined)

create(test_run)

Methods creates test run output for console print

Parameters:test_run (obj) – test run object
Returns:void

util

  • check

Module with check utilities

hydratk.extensions.yoda.util.check.load_json(document)

Methods loads JSON document

Parameters:document (str) – JSON document
Returns:dict
hydratk.extensions.yoda.util.check.load_xml(document)

Methods loads XML document

Parameters:document (str) – XML document
Returns:obj
hydratk.extensions.yoda.util.check.xpath(document, expression, attribute=None, ns={}, get_text=True)

Methods performs XPATH query

Parameters:
  • document (obj) – str or loaded XML document
  • expression (str) – XPATH expression
  • attribute (str) – element attribute
  • ns (dict) – namespaces definition
  • get_text (bool) – get element text content
Returns:

str when get_text = True or attribute != None otherwise XPATH query output

Return type:

obj

hydratk.extensions.yoda.util.check.regex(text, expression)

Methods performs regular expression search

Parameters:
  • text (str) – text
  • expression (str) – regular expression
Returns:

str or list

Return type:

obj

  • data

Module for random data generation

hydratk.extensions.yoda.util.data.gen_number(n_int=10, n_frac=0, positive=True, cnt=1)

Method generates random number

Parameters:
  • n_int (int) – digits for integer part
  • n_frac (int) – digits for fractional part
  • positive (bool) – generate positive number
  • cnt (int) – count of generated samples
Returns:

int, float or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_nondec(n=10, base='hex', cnt=1)

Method generates random number with non-decadical base

Parameters:
  • n (int) – digits
  • base (str) – numeric base bin|oct|hex
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_string(n=10, category='alpha', cnt=1)

Method generates random string

Parameters:
  • n (int) – characters
  • category (str) – category alpha|lower|upper|numeric|alphanumeric|special
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_date(date_format='iso', start=None, end=None, current=None, time_zone=None, cnt=1)

Method generates random date or datetime

Current datetime is generated by default When only start or end of interval is provided, second part is set to current datetime

Parameters:
  • date_format (str) – format iso|unix or any format supported by strftime
  • start (str) – start date with date_format supported by strftime
  • end (str) – end date with date_format suported by strftime
  • current (str) – current year|month|day|hour|minute
  • time_zone (str) – time zone, see pytz documentation for info
  • cnt (int) – count of generated samples
Returns:

int (unix format), str (other formats) or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_ip(version=4, cnt=1)

Method generates random IP address

Parameters:
  • version (int) – protocol version 4|6
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_birth_no(min_age=18, max_age=30, male=True, delimiter=False, cnt=1)

Method generates random birth number

Czech format YYMMDDZZZC

Parameters:
  • min_age (int) – minimum age
  • max_age (int) – maximum age
  • male (bool) – generate male birth number, otherwise female
  • delimiter (bool) – include delimiter /
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_reg_no(cnt=1)

Method generates random registration number

Czech format XXXXXXXX

Parameters:cnt (int) – count of generated samples
Returns:str or list
Return type:obj
hydratk.extensions.yoda.util.data.gen_tax_no(prefix='CZ', src='reg_no', cnt=1)

Method generates random tax number

Czech format CZreg_no or CZbirth_no

Parameters:
  • prefix (str) – prefix
  • src (str) – source reg_no|birth_no
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_account_no(form='nat', country='CZ', prefix=False, bank=None, base_len=10, prefix_len=6, cnt=1)

Method generates random account number

Parameters:
  • form (str) – account format national|iban
  • country (str) – country code used in IBAN
  • prefix (bool) – generate account prefix
  • bank (str) – bank code, generated from db table bank if empty
  • base_len (int) – length of base part, max 10
  • prefix_len (int) – length of prefix part, max 6
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_email(name_len=8, subdomain=None, subdomain_len=6, domain='.com', domain_type='original', cnt=1)

Method generates random email

Parameters:
  • name_len (int) – name length
  • subdomain (str) – subdomain, random generated if empty
  • subdomain_len (int) – subdomain length
  • domain (str) – domain, generated from db table domain if empty
  • domain_type (str) – type of domain original (i.e. .com,.org) or country (i.e. .cz,.de)
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_name(sex='both', tuple_out=True, cnt=1)

Method generates random email

Parameters:
  • sex (str) – sex both|male|female
  • tuple_out (bool) – tuple output (first_name, surname) otherwise str (first_name+surname)
  • cnt (int) – count of generated samples
Returns:

tuple|str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_phone(form='int', cc=420, country=None, ndc=601, sn_len=6, cnt=1)

Method generates random phone number

Parameters:
  • form (str) – number format int|nat international, national
  • cc (int) – country code, generated from db table cc if empty
  • country (str) – country title, country code got from table cc if cc empty
  • ndc (int) – national destination code, random generated if empty or if cc empty
  • sn_len (int) – length of subcriber number
  • cnt (int) – count of generated samples
Returns:

str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data.gen_address(param=None, value=None, street_no_full=True, dict_out=True, cnt=1)

Method generates random address

Database contains czech addresses

Parameters:
  • param (str) – type of address parameter region|district|area|locality|part
  • value (str) – parameter value, searched in db table region|district|area|locality|part czech kraj|okres|oblast|obec|cast obce
  • street_no (str) – generate street number with descriptive and orientation number otherwise descriptive
  • (bool) generate address as dict, otherwise str (street number, part, ZIP code) (dict_out) –
  • cnt (int) – count of generated samples
Returns:

dict|str or list

Return type:

obj

Raises:

error – ValueError

hydratk.extensions.yoda.util.data._get_dsn()

Method gets dsn from config

Parameters:none
Returns:str
hydratk.extensions.yoda.util.data.create_type(title, description=None, col_titles=[])

Method creates data type

Parameters:
  • title (str) – type title
  • description (str) – type description
  • col_titles (list) – list of string, max length 10
Returns:

bool

hydratk.extensions.yoda.util.data.update_type(title, title_new=None, description=None, col_titles_new={})

Method creates data type

Parameters:
  • title (str) – current type title
  • title_new (str) – new type title
  • description (str) – type description
  • col_titles_new (dict) – new column values (key - col id, value - col value)
Returns:

bool

hydratk.extensions.yoda.util.data.delete_type(title, del_records=True)

Method deletes data type

Parameters:
  • title (str) – type title
  • del_records (bool) – delete assigned records in table data
Returns:

bool

hydratk.extensions.yoda.util.data.read_data(data_type, active=1, col_filter={})

Method reads data

Parameters:
  • data_type (str) – data_type
  • active (int) – column active value (1-active, 0-deactive)
  • col_filter (dict) – column values to set filter (key - col id, value - col value)
Returns:

list of dict (key - column title, value - column value)

Return type:

list

hydratk.extensions.yoda.util.data.create_data(data_type, active=1, col_values={})

Method creates data

Parameters:
  • data_type (str) – data_type
  • active (int) – column active value (1-active, 0-deactive)
  • col_values (dict) – column values (key - col id, value - col value)
Returns:

bool

hydratk.extensions.yoda.util.data.update_data(data_type, active=None, col_filter={}, col_values_new={})

Method updates data

Parameters:
  • data_type (str) – data_type
  • active (int) – column active value (1-active, 0-deactive)
  • col_filter (dict) – column values to set filter (key - col id, value - col value)
  • col_values_new (dict) – new column values (key - col id, value - col value)
Returns:

bool

hydratk.extensions.yoda.util.data.delete_data(data_type, active=0, col_filter={})

Method deletes data

Parameters:
  • data_type (str) – data_type
  • active (int) – column active value (1-active, 0-deactive)
  • col_filter (dict) – column values to set filter (key - col id, value - col value)
Returns:

bool