For comparing csv-files, 2d-array with a csv-file or 2d-arrays. For comparing text-files, text variable with a text-file or text variables. Including a sorting module.
Project description
Preparation
Installation
If you already have Python with pip installed, you can simply run:
pip install DataComparerLibrary pip install --upgrade DataComparerLibrary
Also the following pip package is needed:
pip install python-dateutil
Import statement for the DataComparerLibrary in Python
from DataComparerLibrary.datacomparer import DataComparer
DataComparer
Introduction
- The DataComparerLibrary can be used for:
comparing csv-files or text-files
comparing a 2d-matrix with a csv-file or text-file
comparing a csv-file or text-file with a 2d-matrix
comparing 2d-matrices
Comparing Data
Examples of using the DataComparerLibrary for comparing data in Python
Below there are some examples how to call the methods of the DataComparerLibrary in Python:
a = DataComparer a.compare_data_files(self, actual_file, expected_file) a.compare_data_files(self, actual_file, expected_file, delimiter_actual_data=';', delimiter_expected_data=';') a.compare_data_files(self, actual_file, expected_file, delimiter_actual_data='@#@', delimiter_expected_data='@#@') a.compare_data_2d_array_with_file(self, actual_2d_matrix_data_input, expected_file, delimiter_expected_data='\t') a.compare_data_file_with_2d_array(self, actual_file, expected_2d_matrix_data_input, delimiter_actual_data=';') a.compare_data_2d_arrays(self, actual_2d_matrix_data_input, expected_2d_matrix_data_input)
Examples of using the DataComparerLibrary keywords for comparing data in Robot Framework
Below there are some examples how to call the keywords of the DataComparerLibrary in Robot Framework:
*** Settings ***
Library DataComparerLibrary
*** Test Cases ***
Testcase_DataComparer
Examples
*** Keywords ***
Examples
Run Keyword And Continue On Failure DataComparerLibrary.Compare Data Files C:\\Users\\actual.csv C:\\Users\\expected.csv
DataComparerLibrary.Compare Data Files C:\\Users\\actual.csv C:\\Users\\expected.csv delimiter_actual_data=; delimiter_expected_data=;
DataComparerLibrary.Compare Data Files C:\\Users\\actual.csv C:\\Users\\expected.csv delimiter_actual_data=@#@ delimiter_expected_data=@#@
DataComparerLibrary.Compare Data Files C:\\Users\\actual.csv C:\\Users\\expected.csv
DataComparerLibrary.Compare Data 2d Array With File ${actual_2d_matrix_data_input} C:\\Users\\expected.csv delimiter_expected_data=\t
Set Variable ${postcode} 52091
${expected_2d_matrix_data_input}= Evaluate [['NAME', 'STREET', 'NUMBER', 'CITY', 'POSTCODE'], ['JOHN', 'Lund gatan', 10, 'STOCKHOLM', '${postcode}']]
DataComparerLibrary.Compare Data File With 2d Array C:\\Users\\actual.csv ${expected_2d_matrix_data_input} delimiter_actual_data=;
DataComparerLibrary.Compare Data 2d Arrays ${actual_2d_matrix_data_input} ${expected_2d_matrix_data_input}
&{literal_dict}= Create Dictionary {lit_1}=${some_variable}
... {lit_2}='Text with space'
... {version}=${version}
... {build_number}=${build_number}
... {env}=${env}
... {firstname}=${name}
... {capital}='Stockholm'
DataComparerLibrary.Compare Data Files ${actual_input_file_template_literal} ${expected_input_file_template_literal} delimiter_actual_data=; delimiter_expected_data=; template_literals_dict=${literal_dict}
Examples comparing Actual Data with Expected Data
Below there is an example of actual and expected data with some different cases.
Based on current datetime = 2023-09-06 19:04:00 (example):
Actual csv file or 2d-array |
|||||
|---|---|---|---|---|---|
id |
name |
city |
start datetime |
code |
password |
87 |
John |
London |
2019-09-01 10:00:15 |
abc1 |
xxxxxxxx |
88 |
Bert |
Amsterdam |
2023/09/06 19:02:00 |
xxxxxxxx |
|
89 |
Klaas |
Brussel |
23-8-6 12:04:17 |
5ghi |
xxxxxxxx |
90 |
Joe |
Helsinki |
08062025 12:04:17 |
99fg |
xxxxxxxx |
91 |
Mike |
Berlin |
2023/09/06 19:02:00 |
123 |
xxxxxxxx |
92 |
Kurt |
Paris |
2023/09/06 19:02:00 |
123 |
xxxxxxxx |
Expected csv file or 2d-array |
|||||
|---|---|---|---|---|---|
id |
name |
city |
start datetime |
code |
password |
{INTEGER} |
John |
London |
{NOW()-4Y5D:YYYY-MM-DD} |
abc1 |
{PRESENT} |
{INTEGER} |
Bert |
Amsterdam |
{NOW():YYYY/MM/DD} {SKIP} |
{EMPTY} |
{PRESENT} |
{INTEGER} |
Klaas |
Brussel |
{NOW()-1M:YY-M-D} {SKIP} |
5ghi |
{PRESENT} |
{INTEGER} |
Joe |
Helsinki |
{NOW()+1Y9M2D:DDMMYYYY} {SKIP} |
{SKIP} |
{PRESENT} |
{INTEGER} |
{NOT(“Jack”)} |
Berlin |
{NOW():YYYY/MM/DD} {SKIP} |
{NOT(456)} |
{PRESENT} |
{INTEGER} |
{firstname} |
{capital} |
{NOW():YYYY/MM/DD} {SKIP} |
123 |
{PRESENT} |
Comparing Text
Examples of using the DataComparerLibrary for comparing text in Python
Below there are some examples how to call the methods of the DataComparerLibrary in Python:
a = DataComparer a.compare_text_files(self, actual_file, expected_file) a.compare_text_variable_with_text_file(self, actual_text_input, expected_file) a.compare_text_file_with_text_variable(self, actual_file, expected_text_input) a.compare_text_variables(self, actual_text_input, expected_text_input)
Examples of using the DataComparerLibrary keywords for comparing text in Robot Framework
Below there are some examples how to call the keywords of the DataComparerLibrary in Robot Framework:
*** Settings ***
Library DataComparerLibrary
*** Test Cases ***
Testcase_DataComparer
Examples
*** Keywords ***
Examples
Run Keyword And Continue On Failure DataComparerLibrary.Compare Text Files C:\\Users\\actual.txt C:\\Users\\expected.txt
DataComparerLibrary.Compare Text Files C:\\Users\\actual.txt C:\\Users\\expected.txt
DataComparerLibrary.Compare Text Files C:\\Users\\actual.txt C:\\Users\\expected.txt
DataComparerLibrary.Compare Text Files C:\\Users\\actual.txt C:\\Users\\expected.txt
DataComparerLibrary.Compare Text Variable With File ${actual_text_input} C:\\Users\\expected.txt
DataComparerLibrary.Compare Text File With Text Variable C:\\Users\\actual.txt ${expected_text_input}
DataComparerLibrary.Compare Text Variables ${actual_text_input} ${expected_text_input}
DataSorter
Introduction
The DataSorter can be used for sorting records in a csv file or text file.
Default sorting
The default sorting is alphabetically based in ascending order on column 0 on all records.
Special sorting
Examples of using the DataComparerLibrary keywords for sorting data in Robot Framework
Below there are some examples how to call the keywords of the DataComparerLibrary in Robot Framework:
*** Settings ***
Library DataComparerLibrary
*** Test Cases ***
Testcase_DataSorter
Examples
*** Keywords ***
Examples
# sorting examples
#
# Sorting alphabetic on column 0, 5 and 4
${sorting_column_0_5_4} = create list 0 5 4
# Sorting alphabetic on column 4 and 1 and numeric on colum 3
${sorting_column_4_3i_1} = create list 4 ${3} 1
Run Keyword And Continue On Failure DataComparerLibrary.Sort Csv Files C:\\Users\\unsorted.csv C:\\Users\\sorted.csv
DataComparerLibrary.Sort Csv Files C:\\Users\\unsorted.csv C:\\Users\\sorted.csv number_of_header_lines=5 sort_on_columns_list=${sorting_column_0_5_4} number_of_trailer_lines=5 delimiter=;
DataComparerLibrary.Sort Csv Files C:\\Users\\unsorted.csv C:\\Users\\sorted.csv number_of_header_lines=4 sort_on_columns_list=${sorting_column_4_3i_1} delimiter=@#@
DataComparerLibrary.Sort Csv Files C:\\Users\\unsorted.csv C:\\Users\\sorted.csv number_of_trailer_lines=2 delimiter=\t
DataComparerLibrary.Sort Csv Files C:\\Users\\unsorted.csv C:\\Users\\sorted.csv
FileConverter
Introduction
Records in files can be ended by carriage return line feed (CRLF). In some situations separate line feeds (LF) are present within records. For example for an easy way of sorting records this can be a problem.
DataComparerLibrary keywords for preparing data in Robot Framework
The keywords “Remove Separate Lf” and “Replace Separate Lf” support removing/replacing a separate Lf in the data from the input file. The result will be written to an output file.
Examples of using the DataComparerLibrary keywords for preparing data in Robot Framework
Below there are some examples how to call the keywords of the DataComparerLibrary in Robot Framework:
*** Settings ***
Library DataComparerLibrary
*** Test Cases ***
Testcase_FileConverter
Remove Separate LF From Data In File
Replace Separated LF With Character Or String From Data In File
*** Keywords ***
Remove Separate LF From Data In File
DataComparerLibrary.Remove Separate Lf ${path_actual_input_files}\\input_file_with_lf.txt ${path_actual_output_files}\\output_file_without_lf.txt
Replace Separated LF With Character Or String From Data In File
DataComparerLibrary.Replace Separate Lf ${input_file_with_separate_lf} ${output_file_lf_replaced_by_character_or_string} ${replacement_string}
DataComparerLibrary.Replace Separate Lf input_file_with_separate_lf.txt output_file_lf_replaced_by_character_or_string.txt abc
DataComparerLibrary.Replace Separate Lf input_file_with_separate_lf.txt output_file_lf_replaced_by_character_or_string.txt x
DataComparerLibrary.Replace Separate Lf input_file_with_separate_lf.txt output_file_lf_replaced_by_character_or_string.txt ${SPACE}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datacomparerlibrary-0.855.tar.gz.
File metadata
- Download URL: datacomparerlibrary-0.855.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85629daa8dbfa01d2aa5600abafd701d2dcd0423766aa3bbc4ec471a51fda0f7
|
|
| MD5 |
c0c0a864841e960926efda27fff048df
|
|
| BLAKE2b-256 |
931980a3a77a50c7f73849831650d855b25f1d5cfa7538aec762095e505172a3
|
File details
Details for the file datacomparerlibrary-0.855-py3-none-any.whl.
File metadata
- Download URL: datacomparerlibrary-0.855-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffb84cada6044a68d2d971e8b3f5e3a47f53c94fb931d5b64bb39f5e02c793a4
|
|
| MD5 |
4256f66009b810220726aa9f9426c4aa
|
|
| BLAKE2b-256 |
2c2120b3509c18fed0ce1719a8835f1b4c38aaea3fe4a458504779671ce53378
|