No project description provided
Project description
A library that normalizes simple SQL queries and compares them first by equality of the normalized string and then using the cosette API.
[Beta in Development!]
- Submit bug reports and features requests at: https://github.com/ValentinHerrmann/sql_testing_tools
- PyPi-Package available at: https://pypi.org/project/sql-testing-tools/
Getting started
Use the following code to import the SQL Testing Tools to your project:
# ensure to always use the latest version of sql_testing_tools
import os
os.system('pip install -U sql_testing_tools')
# import sql_testing_tools
import sql_testing_tools.BaseAccess as Ba
import sql_testing_tools.Helper as He
On global level of your test class, set the SQLite database you want to use (bases must be located in the repository of the test class, no DBs contained in sql_testing_tools).
import unittest
class TestClass(unittest.TestCase):
Ba.setDBName("databases/ladepunkte.db")
The following methods are available for use in test methods:
try:
Ba.runAndGetStringTable_fromFile("sqlfile.sql")
except Exception as e:
# the execution failed
# (usually due to syntax or database errors)
self.fail(e)
# (optional) set the files to be compared. The sql strings will
# be normalized and used for all following methods (to improve
# performance), until new files are set. Arguments that are
# None or "" are ignored and the sql string remains the same.
# Raises an Exception if one of the files is empty.
setup("sqlfile.sql","solution.sql")
# All following methods call setup(sql,sol) before executing
# anything else. Call without arguments to keep the last
# normalized sql strings (and improve performance).
# Each check was successfull if "" is returned. Returns a
# German error message if not.
# Each method compares the normalized string between the start
# keyword and the next keyword or ;
res = He.checkColumns() # starts to search at keyword "SELECT"
res = He.checkTables() # starts to search at keyword "FROM"
res = He.checkCondition() # starts to search at keyword "WHERE"
res = He.checkOrder() # starts to search at keyword "ORDER BY"
res = He.checkGroup() # starts to search at keyword "GROUP BY"
# can not be called with new sql files
res = checkKeywords("startKeyword",["end","keywords"])
# compares equality of the full normalized sql strings and if
# not equal uses the Cosette API (cosette.cs.washington.edu)
# for comparison. A file 'cosette_apikey.txt' with only the
# apikey in it on root level of the test repository is required
# to use this feature. If not existant, only the string comparison
# is performed.
# Warning: Cosette is not maintained!
res = checkEquality()
Changelog
V0.2.4
- Added more check methods for single parts of queries: checkColumns, checkTables, checkCondition, checkOrder, checkGroup, checkKeywords
V 0.2.3
- fix: ASC/DESC in ORDER BY (also with multiple columns and order directions), no direction treated as ASC
- Verified that ; and whitespaces, linebreaks at end of query are ignored
V 0.2.2
- Support LIKE
- Support '<=' and '>=' (geq and leq)
V 0.2.1
- Support LIMIT
V 0.1.9 + 0.2.0
- Support ORDER BY
V 0.1.8
- Fixed linebreak problems: Linebreaks are now converted into whitespaces before parsing where tokens
V 0.1.6 + V 0.1.7
- Fixed import error to ensure imports working in different environments
V 0.1.4 + V 0.1.5
- Chained conditions (with AND,OR and Paranthesises) in WHERE statement
- Aggregate Functions
V 0.1.3
- SELECT: columns with our without table prefix
- FROM: one or more table from DB; no queries as tables!
- WHERE: single conditions; no Paranthesises!
- GROUP BY one or more columns
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 sql_testing_tools-0.2.4a0.tar.gz.
File metadata
- Download URL: sql_testing_tools-0.2.4a0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd26bc5b9201272b0c77bbe9cc23331cdac3522afcee2dc1fa05de297c4e0045
|
|
| MD5 |
33a2c12d1406e83c6468a6cc410da102
|
|
| BLAKE2b-256 |
ea4b57c04d7bd1798ca9c90c1b3624dbb2c805582a49a09d867ac6159230a79e
|
Provenance
The following attestation bundles were made for sql_testing_tools-0.2.4a0.tar.gz:
Publisher:
publish.yml on ValentinHerrmann/sql_testing_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_testing_tools-0.2.4a0.tar.gz -
Subject digest:
cd26bc5b9201272b0c77bbe9cc23331cdac3522afcee2dc1fa05de297c4e0045 - Sigstore transparency entry: 167843543
- Sigstore integration time:
-
Permalink:
ValentinHerrmann/sql_testing_tools@3a9aa7e16720f84e8b626664f24ff8006ae298eb -
Branch / Tag:
refs/tags/0.2.4.a - Owner: https://github.com/ValentinHerrmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3a9aa7e16720f84e8b626664f24ff8006ae298eb -
Trigger Event:
release
-
Statement type:
File details
Details for the file sql_testing_tools-0.2.4a0-py3-none-any.whl.
File metadata
- Download URL: sql_testing_tools-0.2.4a0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99ebb3320d03b694dc24ada0c6603477c0020db81b4d58a389fe933465b141ed
|
|
| MD5 |
5b5287d3cb17adf2b9a8bc01b750a497
|
|
| BLAKE2b-256 |
78d45f6eef0ba1a527c5e9dacd6a3cd248f6596db1748cbdc365a07ec43c0a75
|
Provenance
The following attestation bundles were made for sql_testing_tools-0.2.4a0-py3-none-any.whl:
Publisher:
publish.yml on ValentinHerrmann/sql_testing_tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sql_testing_tools-0.2.4a0-py3-none-any.whl -
Subject digest:
99ebb3320d03b694dc24ada0c6603477c0020db81b4d58a389fe933465b141ed - Sigstore transparency entry: 167843545
- Sigstore integration time:
-
Permalink:
ValentinHerrmann/sql_testing_tools@3a9aa7e16720f84e8b626664f24ff8006ae298eb -
Branch / Tag:
refs/tags/0.2.4.a - Owner: https://github.com/ValentinHerrmann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3a9aa7e16720f84e8b626664f24ff8006ae298eb -
Trigger Event:
release
-
Statement type: