Package unittests :: Module unittest_helper
[hide private]
[frames] | no frames]

Module unittest_helper

source code

This module includes helper variables and methods for the unittests.

Functions [hide private]
 
compare_non_array_data(cls, data1, data2, method_name, is_almost)
Compares non-array data type
source code
 
compare_array_data(cls, array1, array2, method_name, is_almost)
Compares 1d array data type
source code
 
compare_2d_array_data(cls, array1, array2, method_name, is_almost)
Compares 2d array data type
source code
 
compare_data(is_array_type, cls, rand_data, ret_data, method_name, is_almost)
Compares data type(non-array, 1d or 2d array)
source code
 
compare_tuples(cls, type_params, rand_tuple, ret_tuple, method_name, is_almost)
Compares tuples that can contain one or more data types
source code
 
compare_set_of_tuples(cls, type_params, tuple_set1, tuple_set2, method_name, is_almost)
Compares set of tuples that can contain one or more tuples that can contain one or more data types
source code
string @return sql representation of the given type
convert_char(v)
Converts char to sql representation
source code
string @return sql representation of the given type
convert_bool_and_numeric(v)
Converts bool and numeric types to sql representation
source code
string @return sql representation of the given type
convert_char_array(v)
Converts char array to sql representation
source code
string @return sql representation of the given type
convert_bool_and_numeric_array(v)
Converts bool and numeric array types to sql representation
source code
string @return sql representation of the given type
convert_bool_and_numeric_array_without_quotes(v)
Converts bool and numeric array types to sql representation without quotes
source code
string @return sql representation of the given type
convert_bool_and_numeric_2d_array(v)
Converts bool and numeric 2d array types to sql representation
source code
 
write_non_array_data(b, data, data_size, pack_fnc)
Writes non-array data to the buffer
source code
 
write_array_data(b, data_array, elm_size, elm_type, pack_fnc)
Writes 1d array data to the buffer
source code
 
write_2d_array_data(b, data_array, elm_size, elm_type, pack_fnc)
Writes 2d array data to the buffer
source code
 
write_rand_data(is_array_type, b, rand_data, elm_size, elm_type, pack_fnc)
Writes data(non-array, 1d or 2d array) to the buffer
source code
data
create_rand_data(is_array_type, random_fnc)
Creates random data(non-array, 1d or 2d array)
source code
char
create_random_char()
Creates random char
source code
bool
create_random_bool()
Creates random bool
source code
int2
create_random_int2()
Creates random int2
source code
int4
create_random_int4()
Creates random int4
source code
int8
create_random_int8()
Creates random int8
source code
float4
create_random_float4()
Creates random float4
source code
float8
create_random_float8()
Creates random float8
source code
array
create_1d_generic_array(create_random_elm_fnc)
Creates 1d array
source code
array
create_2d_generic_array(create_random_elm_fnc)
Creates 2d array
source code
tuple
get_vdb_tuple(t, convert_fnc, sql_type)
Includes a function(to convert data to sql type) and sql type of data to the given type param
source code
 
enumerate_and_test_tuples(test_fnc, type_params, oids, limit_test)
This method enumerates all subsets of the given types and creates all combination of different schemas (e.g.
source code
 
test_tuples_with_non_array_data(test_fnc, limit_test, sql_interaction)
This method tests tuples with possible non-array data type combinations by calling test_fnc.
source code
 
test_tuples_with_array_data(test_fnc, limit_test, sql_interaction)
This method tests tuples with possible array data type combinations by calling test_fnc.
source code
 
test_tuples_with_data(test_fnc, limit_test, sql_interaction)
This method tests tuples with possible non-array and array data type combinations by calling test_fnc.
source code
string
create_table_from_fields(type_params)
From given type params, this method creates "create table query statement"
source code
Variables [hide private]
  limit_test = 200
  tuple_size = 1000
  test_num = 1000
  vec_size = 100
  row_num = 30
  col_num = 50
  type_non_array = 0
  type_1d_array = 1
  type_2d_array = 2
  with_sql = 1
  without_sql = 0
  size_int = 4
  struct_int4 = struct.Struct('>i')
  temp_table_name = 'temp_tbl_for_test'
  temp_file_name = "temp_file.dat"
  exact_equal = 0
  almost_equal = 1
  almost_eq_places = 6
  enumerate_fnc = lambda x:
  char_type_param = type_non_array, oid_dict [charoid] [data_siz...
  bool_type_param = type_non_array, oid_dict [booloid] [data_siz...
  int2_type_param = type_non_array, oid_dict [int2oid] [data_siz...
  int4_type_param = type_non_array, oid_dict [int4oid] [data_siz...
  int8_type_param = type_non_array, oid_dict [int8oid] [data_siz...
  float4_type_param = type_non_array, oid_dict [float4oid] [data...
  float8_type_param = type_non_array, oid_dict [float8oid] [data...
  char_array_type_param = type_1d_array, oid_dict [charoid] [dat...
  bool_array_type_param = type_1d_array, oid_dict [booloid] [dat...
  int2_array_type_param = type_1d_array, oid_dict [int2oid] [dat...
  int4_array_type_param = type_1d_array, oid_dict [int4oid] [dat...
  int8_array_type_param = type_1d_array, oid_dict [int8oid] [dat...
  float4_array_type_param = type_1d_array, oid_dict [float4oid] ...
  float8_array_type_param = type_1d_array, oid_dict [float8oid] ...
  float8_2d_array_type_param = type_2d_array, oid_dict [float8oi...
  char_vdb_type_param = get_vdb_tuple(char_type_param, convert_c...
  bool_vdb_type_param = get_vdb_tuple(bool_type_param, convert_b...
  int2_vdb_type_param = get_vdb_tuple(int2_type_param, convert_b...
  int4_vdb_type_param = get_vdb_tuple(int4_type_param, convert_b...
  int8_vdb_type_param = get_vdb_tuple(int8_type_param, convert_b...
  float4_vdb_type_param = get_vdb_tuple(float4_type_param, conve...
  float8_vdb_type_param = get_vdb_tuple(float8_type_param, conve...
  bool_array_vdb_type_param = get_vdb_tuple(bool_array_type_para...
  int2_array_vdb_type_param = get_vdb_tuple(int2_array_type_para...
  int4_array_vdb_type_param = get_vdb_tuple(int4_array_type_para...
  int8_array_vdb_type_param = get_vdb_tuple(int8_array_type_para...
  float4_array_vdb_type_param = get_vdb_tuple(float4_array_type_...
  float8_array_vdb_type_param = get_vdb_tuple(float8_array_type_...
  float8_2d_array_vdb_type_param = get_vdb_tuple(float8_2d_array...
Function Details [hide private]

compare_non_array_data(cls, data1, data2, method_name, is_almost)

source code 

Compares non-array data type

Parameters:
  • cls (class) - unittest class for assertEqual functions
  • data1 (data) - data1 to compare
  • data2 (data) - data2 to compare
  • method_name (string) - name of the method
  • is_almost (bool) - whether we want exact comparison or almost comparison

compare_array_data(cls, array1, array2, method_name, is_almost)

source code 

Compares 1d array data type

Parameters:
  • cls (class) - unittest class for assertEqual functions
  • array1 (array) - array1 to compare
  • array2 (array) - array2 to compare
  • method_name (string) - name of the method
  • is_almost (bool) - whether we want exact comparison or almost comparison

compare_2d_array_data(cls, array1, array2, method_name, is_almost)

source code 

Compares 2d array data type

Parameters:
  • cls (class) - unittest class for assertEqual functions
  • array1 (array) - array1 to compare
  • array2 (array) - array2 to compare
  • method_name (string) - name of the method
  • is_almost (bool) - whether we want exact comparison or almost comparison

compare_data(is_array_type, cls, rand_data, ret_data, method_name, is_almost)

source code 

Compares data type(non-array, 1d or 2d array)

Parameters:
  • is_array_type (number) - whether data is non-array, 1d or 2d array
  • cls (class) - unittest class for assertEqual functions
  • rand_data (data) - data to compare
  • ret_data (data) - data to compare
  • method_name (string) - name of the method
  • is_almost (bool) - whether we want exact comparison or almost comparison

compare_tuples(cls, type_params, rand_tuple, ret_tuple, method_name, is_almost)

source code 

Compares tuples that can contain one or more data types

Parameters:
  • cls (class) - unittest class for assertEqual functions
  • type_params (tuple) - contains information about the data types in the tuple
  • rand_tuple (array) - array to compare
  • ret_tuple (array) - array to compare
  • method_name (string) - name of the method
  • is_almost (bool) - whether we want exact comparison or almost comparison

compare_set_of_tuples(cls, type_params, tuple_set1, tuple_set2, method_name, is_almost)

source code 

Compares set of tuples that can contain one or more tuples that can contain one or more data types

Parameters:
  • cls (class) - unittest class for assertEqual functions
  • type_params (tuple) - contains information about the data types in the tuple
  • tuple_set1 (array) - array to compare
  • tuple_set2 (array) - array to compare
  • method_name (string) - name of the method
  • is_almost (bool) - whether we want exact comparison or almost comparison

convert_char(v)

source code 

Converts char to sql representation

Parameters:
  • v (char) - character
Returns: string @return sql representation of the given type

convert_bool_and_numeric(v)

source code 

Converts bool and numeric types to sql representation

Parameters:
  • v (bool or a numeric type) - bool or a numeric type
Returns: string @return sql representation of the given type

convert_char_array(v)

source code 

Converts char array to sql representation

Parameters:
  • v (char array) - character array
Returns: string @return sql representation of the given type

convert_bool_and_numeric_array(v)

source code 

Converts bool and numeric array types to sql representation

Parameters:
  • v (bool or a numeric array type) - bool or a numeric array type
Returns: string @return sql representation of the given type

convert_bool_and_numeric_array_without_quotes(v)

source code 

Converts bool and numeric array types to sql representation without quotes

Parameters:
  • v (bool or a numeric array type) - bool or a numeric array type
Returns: string @return sql representation of the given type

convert_bool_and_numeric_2d_array(v)

source code 

Converts bool and numeric 2d array types to sql representation

Parameters:
  • v (bool or a numeric 2d array type) - bool or a numeric 2d array type
Returns: string @return sql representation of the given type

write_non_array_data(b, data, data_size, pack_fnc)

source code 

Writes non-array data to the buffer

Parameters:
  • b (buffer) - buffer that the data will be written
  • data (data) - non-array type data
  • data_size (number) - size of the data
  • pack_fnc (function) - pack function for the data

write_array_data(b, data_array, elm_size, elm_type, pack_fnc)

source code 

Writes 1d array data to the buffer

Parameters:
  • b (buffer) - buffer that the data will be written
  • data_array (data) - 1d array type data
  • elm_size (number) - size of the data
  • elm_type (number) - oid of the element
  • pack_fnc (function) - pack function for the data

write_2d_array_data(b, data_array, elm_size, elm_type, pack_fnc)

source code 

Writes 2d array data to the buffer

Parameters:
  • b (buffer) - buffer that the data will be written
  • data_array (data) - 2d array type data
  • elm_size (number) - size of the data
  • elm_type (number) - oid of the element
  • pack_fnc (function) - pack function for the data

write_rand_data(is_array_type, b, rand_data, elm_size, elm_type, pack_fnc)

source code 

Writes data(non-array, 1d or 2d array) to the buffer

Parameters:
  • is_array_type (number) - whether data is non-array, 1d or 2d array
  • b (buffer) - buffer that the data will be written
  • rand_data (data) - non-array, 1d or 2d array type data
  • elm_size (number) - size of the data
  • elm_type (number) - oid of the element
  • pack_fnc (function) - pack function for the data

create_rand_data(is_array_type, random_fnc)

source code 

Creates random data(non-array, 1d or 2d array)

Parameters:
  • is_array_type (number) - whether data is non-array, 1d or 2d array
  • random_fnc (function) - random function to create a random element
Returns: data
returns random data(non-array, 1d or 2d array)

create_random_char()

source code 

Creates random char

Returns: char
random char

create_random_bool()

source code 

Creates random bool

Returns: bool
random bool

create_random_int2()

source code 

Creates random int2

Returns: int2
random int2

create_random_int4()

source code 

Creates random int4

Returns: int4
random int4

create_random_int8()

source code 

Creates random int8

Returns: int8
random int8

create_random_float4()

source code 

Creates random float4

Returns: float4
random float4

create_random_float8()

source code 

Creates random float8

Returns: float8
random float8

create_1d_generic_array(create_random_elm_fnc)

source code 

Creates 1d array

Parameters:
  • create_random_elm_fnc (function) - function to create random elements of the array
Returns: array
random 1d array with the given type

create_2d_generic_array(create_random_elm_fnc)

source code 

Creates 2d array

Parameters:
  • create_random_elm_fnc (function) - function to create random elements of the array
Returns: array
random 2d array with the given type

get_vdb_tuple(t, convert_fnc, sql_type)

source code 

Includes a function(to convert data to sql type) and sql type of data to the given type param

Parameters:
  • t (tuple) - type param
  • convert_fnc (function) - function to convert data to the sql representation
  • sql_type (string) - data type in sql (e.g. 'char' for char, 'float8[]' for float8 array)
Returns: tuple
new type param that includes convert function and sql type

enumerate_and_test_tuples(test_fnc, type_params, oids, limit_test)

source code 

This method enumerates all subsets of the given types and creates all combination of different schemas (e.g. [char, int2] or [char, int4, float8array]). Then, for each combination, test method(test_fnc) is called. # of tests is: 2 ** len(type_params) - 1

Parameters:
  • test_fnc (function) - name of the generic test function
  • type_params (tuple) - contains information(is_array_type, elm_size, random_fnc, elm_type, pack_fnc) about each data type in the tuple.
  • oids (tuple) - oids of the data types in the tuple
  • limit_test (number) - when enumerations are too many to execute, limit_test is used to limit the number of enumerations

test_tuples_with_non_array_data(test_fnc, limit_test, sql_interaction)

source code 

This method tests tuples with possible non-array data type combinations by calling test_fnc. Since there are 7 non-array data types, all combinations produce 127 different schema. Therefore, this method includes min(127, limit_test) tests

Parameters:
  • test_fnc (function) - name of the generic test function
  • limit_test (number) - when enumerations are too many to execute, limit_test is used to limit the number of enumerations
  • sql_interaction (bool) - whether test involves postgres or not

test_tuples_with_array_data(test_fnc, limit_test, sql_interaction)

source code 

This method tests tuples with possible array data type combinations by calling test_fnc. Since there are 8 array data types(for the ones with sql interaction, we dont use char arrays, since they are interpreted as strings, so it is 7), all combinations produce 255(127) different schema. Therefore, this method includes min(255(127), limit_test) tests

Parameters:
  • test_fnc (function) - name of the generic test function
  • limit_test (number) - when enumerations are too many to execute, limit_test is used to limit the number of enumerations
  • sql_interaction (bool) - whether test involves postgres or not

test_tuples_with_data(test_fnc, limit_test, sql_interaction)

source code 

This method tests tuples with possible non-array and array data type combinations by calling test_fnc. Since there are 7 non-array and 8 array data types(for the ones with sql interaction, we dont use char arrays, since they are interpreted as strings, so it is 7), all combinations produce 2 ** 15 - 1(2 ** 14 - 1) different schema. Therefore, this method includes min(2 ** 15 - 1(2 ** 14 - 1), limit_test) tests

Parameters:
  • test_fnc (function) - name of the generic test function
  • limit_test (number) - when enumerations are too many to execute, limit_test is used to limit the number of enumerations
  • sql_interaction (bool) - whether test involves postgres or not

create_table_from_fields(type_params)

source code 

From given type params, this method creates "create table query statement"

Parameters:
  • type_params (array) - type param for each data type in the query
Returns: string
create table statement

Variables Details [hide private]

char_type_param

Value:
type_non_array, oid_dict [charoid] [data_size_field], create_random_ch\
ar, charoid, struct_char.pack

bool_type_param

Value:
type_non_array, oid_dict [booloid] [data_size_field], create_random_bo\
ol, booloid, struct_bool.pack

int2_type_param

Value:
type_non_array, oid_dict [int2oid] [data_size_field], create_random_in\
t2, int2oid, struct_int2.pack

int4_type_param

Value:
type_non_array, oid_dict [int4oid] [data_size_field], create_random_in\
t4, int4oid, struct_int4.pack

int8_type_param

Value:
type_non_array, oid_dict [int8oid] [data_size_field], create_random_in\
t8, int8oid, struct_int8.pack

float4_type_param

Value:
type_non_array, oid_dict [float4oid] [data_size_field], create_random_\
float4, float4oid, struct_float4.pack

float8_type_param

Value:
type_non_array, oid_dict [float8oid] [data_size_field], create_random_\
float8, float8oid, struct_float8.pack

char_array_type_param

Value:
type_1d_array, oid_dict [charoid] [data_size_field], create_random_cha\
r, charoid, struct_char.pack

bool_array_type_param

Value:
type_1d_array, oid_dict [booloid] [data_size_field], create_random_boo\
l, booloid, struct_bool.pack

int2_array_type_param

Value:
type_1d_array, oid_dict [int2oid] [data_size_field], create_random_int\
2, int2oid, struct_int2.pack

int4_array_type_param

Value:
type_1d_array, oid_dict [int4oid] [data_size_field], create_random_int\
4, int4oid, struct_int4.pack

int8_array_type_param

Value:
type_1d_array, oid_dict [int8oid] [data_size_field], create_random_int\
8, int8oid, struct_int8.pack

float4_array_type_param

Value:
type_1d_array, oid_dict [float4oid] [data_size_field], create_random_f\
loat4, float4oid, struct_float4.pack

float8_array_type_param

Value:
type_1d_array, oid_dict [float8oid] [data_size_field], create_random_f\
loat8, float8oid, struct_float8.pack

float8_2d_array_type_param

Value:
type_2d_array, oid_dict [float8oid] [data_size_field], create_random_f\
loat8, float8oid, struct_float8.pack

char_vdb_type_param

Value:
get_vdb_tuple(char_type_param, convert_char, 'char')

bool_vdb_type_param

Value:
get_vdb_tuple(bool_type_param, convert_bool_and_numeric, 'bool')

int2_vdb_type_param

Value:
get_vdb_tuple(int2_type_param, convert_bool_and_numeric, 'int2')

int4_vdb_type_param

Value:
get_vdb_tuple(int4_type_param, convert_bool_and_numeric, 'int4')

int8_vdb_type_param

Value:
get_vdb_tuple(int8_type_param, convert_bool_and_numeric, 'int8')

float4_vdb_type_param

Value:
get_vdb_tuple(float4_type_param, convert_bool_and_numeric, 'float4')

float8_vdb_type_param

Value:
get_vdb_tuple(float8_type_param, convert_bool_and_numeric, 'float8')

bool_array_vdb_type_param

Value:
get_vdb_tuple(bool_array_type_param, convert_bool_and_numeric_array, '\
bool[]')

int2_array_vdb_type_param

Value:
get_vdb_tuple(int2_array_type_param, convert_bool_and_numeric_array, '\
int2[]')

int4_array_vdb_type_param

Value:
get_vdb_tuple(int4_array_type_param, convert_bool_and_numeric_array, '\
int4[]')

int8_array_vdb_type_param

Value:
get_vdb_tuple(int8_array_type_param, convert_bool_and_numeric_array, '\
int8[]')

float4_array_vdb_type_param

Value:
get_vdb_tuple(float4_array_type_param, convert_bool_and_numeric_array,\
 'float4[]')

float8_array_vdb_type_param

Value:
get_vdb_tuple(float8_array_type_param, convert_bool_and_numeric_array,\
 'float8[]')

float8_2d_array_vdb_type_param

Value:
get_vdb_tuple(float8_2d_array_type_param, convert_bool_and_numeric_2d_\
array, 'float8[][]')