Skip to main content

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!]

Build and Test Build and Test

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sql_testing_tools-0.2.4a0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sql_testing_tools-0.2.4a0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

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

Hashes for sql_testing_tools-0.2.4a0.tar.gz
Algorithm Hash digest
SHA256 cd26bc5b9201272b0c77bbe9cc23331cdac3522afcee2dc1fa05de297c4e0045
MD5 33a2c12d1406e83c6468a6cc410da102
BLAKE2b-256 ea4b57c04d7bd1798ca9c90c1b3624dbb2c805582a49a09d867ac6159230a79e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sql_testing_tools-0.2.4a0.tar.gz:

Publisher: publish.yml on ValentinHerrmann/sql_testing_tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sql_testing_tools-0.2.4a0-py3-none-any.whl.

File metadata

File hashes

Hashes for sql_testing_tools-0.2.4a0-py3-none-any.whl
Algorithm Hash digest
SHA256 99ebb3320d03b694dc24ada0c6603477c0020db81b4d58a389fe933465b141ed
MD5 5b5287d3cb17adf2b9a8bc01b750a497
BLAKE2b-256 78d45f6eef0ba1a527c5e9dacd6a3cd248f6596db1748cbdc365a07ec43c0a75

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page