tests package

Submodules

tests.basetest module

Created on 2021-08-19

@author: wf

class tests.basetest.Basetest(methodName='runTest')[source]

Bases: unittest.case.TestCase

base test case

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

static inPublicCI()[source]

are we running in a public Continuous Integration Environment?

static isUser(name: str)[source]

Checks if the system has the given name

setUp(debug=False, profile=True)[source]

setUp test environment

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

class tests.basetest.Profiler(msg, profile=True)[source]

Bases: object

simple profiler

construct me with the given msg and profile active flag

Parameters:
  • msg (str) – the message to show if profiling is active
  • profile (bool) – True if messages should be shown
time(extraMsg='')[source]

time the action and print if profile is active

tests.testEntityManager module

Created on 2021-07-23

@author: wf

class tests.testEntityManager.TestEntityManager(methodName='runTest')[source]

Bases: tests.basetest.Basetest

test the entity manager wrapper

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

checkItem(item1, item2, attrs, msg)[source]
configure(config: lodstorage.storageconfig.StorageConfig)[source]
testEntityManager()[source]

test the entity Manager handling

testStoreMode()[source]

test store mode display

tests.testJson module

Created on 2020-09-12

@author: wf

class tests.testJson.ServerConfig[source]

Bases: lodstorage.jsonable.JSONAble

class tests.testJson.TestJsonAble(methodName='runTest')[source]

Bases: tests.basetest.Basetest

test JSON serialization with JsonAble mixin

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

check(manager, manager1, listName, debugLimit)[source]

check that the list of the two managers are the same

dumpListOfDicts(listOfDicts, limit)[source]
setUp()[source]

setUp test environment

testIssue22()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/22 Regression: storeToJsonFile and restoreFromJsonFile missing in JSONAble

testIssue27_Lookup()[source]

add Lookup map option

testIssue30_SampleLimited()[source]

tests if the json export is correctly limited to the fields that are used in the samples

testJsonAble()[source]

test JSONAble

testPluralName()[source]
testRestoreFromJsonStr()[source]

Tests restoring a JsonAbleList form a json string

testRoyals()[source]

test Royals example

testSingleQuoteToDoubleQuoteStackoverflow()[source]
see
testSingleToDoubleQuote()[source]
testStoreAndRestore()[source]

test storing and restoring from a JSON file https://github.com/WolfgangFahl/pyLoDStorage/issues/21

tests.testPandas module

Created on 2021-06-07

@author: mk

class tests.testPandas.TestPandas(methodName='runTest')[source]

Bases: tests.basetest.Basetest

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

testIssue25()[source]

see https://github.com/WolfgangFahl/pyLoDStorage/issues/25

tests.testSPARQL module

Created on 2020-08-14

@author: wf

class tests.testSPARQL.TestSPARQL(methodName='runTest')[source]

Bases: tests.basetest.Basetest

Test SPARQL access e.g. Apache Jena via Wrapper

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

checkErrors(errors, expected=0)[source]

check the given list of errors - print any errors if there are some and after that assert that the length of the list of errors is zero

Parameters:errors (list) – the list of errors to check
getJena(mode='query', debug=False, typedLiterals=False, profile=False)[source]

get the jena endpoint for the given mode

Parameters:
  • mode (string) – query or update
  • debug (boolean) – True if debug information should be output
  • typedLiterals (boolean) – True if INSERT DATA SPARQL commands should use typed literals
  • profile (boolean) – True if profile/timing information should be shown
testControlEscape()[source]

check the control-escaped version of an UTF-8 string

testDob()[source]

test the DOB (date of birth) function that converts from ISO-Date to datetime.date

testEscapeStringContent()[source]

test handling of double quoted strings

testIssue20And76()[source]

see https://github.com/WolfgangFahl/pyLoDStorage/issues/20 add fixNone option to SPARQL results (same functionality as in SQL)

SPARQL GET method support

testIssue7()[source]

test conversion of dates with timezone info

testJenaInsert()[source]

test a Jena INSERT DATA

testJenaQuery()[source]

test Apache Jena Fuseki SPARQL endpoint with example SELECT query

testListOfDictInsert()[source]

test inserting a list of Dicts and retrieving the values again using a person based example instead of https://en.wikipedia.org/wiki/FOAF_(ontology)

we use an object oriented derivate of FOAF with a focus on datatypes

testListOfDictSpeed()[source]

test the speed of adding data

testSPARQLErrorMessage()[source]

test error handling see https://stackoverflow.com/questions/63486767/how-can-i-get-the-fuseki-api-via-sparqlwrapper-to-properly-report-a-detailed-err

testStackoverflow55961615Query()[source]

see https://stackoverflow.com/questions/55961615/how-to-integrate-wikidata-query-in-python https://stackoverflow.com/a/69771615/1497139

testStackoverflow71444069()[source]

https://stackoverflow.com/questions/71444069/create-csv-from-result-of-a-for-google-colab/71548650#71548650

testWikdata()[source]

check wikidata

test_query_with_authentication()[source]

tests querying an endpoint that requires authentication

tests.testSqlite3 module

Created on 2020-08-24

@author: wf

class tests.testSqlite3.TestSQLDB(methodName='runTest')[source]

Bases: tests.basetest.Basetest

Test the SQLDB database wrapper

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

checkListOfRecords(listOfRecords, entityName, primaryKey=None, executeMany=True, fixNone=False, fixDates=False, debug=False, doClose=True)[source]

check the handling of the given list of Records

Parameters:
  • listOfRecords (list) – a list of dicts that contain the data to be stored
  • entityName (string) – the name of the entity type to be used as a table name
  • primaryKey (string) – the name of the key / column to be used as a primary key
  • executeMany (boolean) – True if executeMany mode of sqlite3 should be used
  • fixNone (boolean) – fix dict entries that are undefined to have a “None” entry
  • debug (boolean) – True if debug information e.g. CREATE TABLE and INSERT INTO commands should be shown
  • doClose (boolean) – True if the connection should be closed
static getSampleTableDB(withDrop=False, debug=False, failIfTooFew=False, sampleSize=1000)[source]
testBackup()[source]

test creating a backup of the SQL database

testBindingError()[source]

test list of Records with incomplete record leading to “You did not supply a value for binding 2” see https://bugs.python.org/issue41638

testCopy()[source]

test copying databases into another database

testEntityInfo()[source]

test creating entityInfo from the sample record

testIssue110()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/110

testIssue13_setNoneValue()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/13 set None value for undefined LoD entries

testIssue14_execute()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/14

offer execute wrapper directly via sqlDB

testIssue15()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/15

auto create view ddl in mergeschema

testIssue16()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/16 allow to only warn if samplerecordcount is higher than number of available records

testIssue18()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/18

testIssue41()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/41 improve error message when create table command fails

testIssue87AllowUsingQueryWithGenerator()[source]

test the query gen approach

testListOfCities()[source]

test sqlite3 with some 120000 city records

testQueryParams()[source]

test Query Params

testSqlite3()[source]

test sqlite3 with a few records from the royal family

testSqllite3Speed()[source]

test sqlite3 speed with some 100000 artificial sample records consisting of two columns with a running index

testUniqueConstraint()[source]

test for https://github.com/WolfgangFahl/pyLoDStorage/issues/4 sqlite3.IntegrityError: UNIQUE constraint failed: … show debug info

tests.testTrulyTabular module

Created on 2022-03-4

@author: wf

class tests.testTrulyTabular.TestTrulyTabular(methodName='runTest')[source]

Bases: unittest.case.TestCase

test Truly tabular analysis

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

documentQuery(tt, query, show=True, formats=['mediawiki'])[source]

document the given query for the given TrueTabular instance

handleServiceUnavailable(ex, endpointConf)[source]

handle service unavailable

Parameters:
  • ex (Exception) – the exception to handle
  • endpointConf (Endpoint) – the endpoint for which there is a problem
setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

testCount()[source]

test the count function of truly tabular

testGenerateSparqlQuery()[source]

test Generating a SPARQL query

testGetFirst()[source]

test the get First helper function

testGetItemsByLabel()[source]

try getting items by label

testGetPropertiesById()[source]

try getting properties by label

testGetPropertiesByLabel()[source]

try getting properties by label

testMostFrequentProperties()[source]

test getting the most frequent properties for some Wikidata Item types

testSyntaxHighlighting()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/81

testTrulyTabularTables()[source]

test Truly Tabular for different tabular queries

tests.test_Plot module

Created on 2020-07-05

@author: wf

class tests.test_Plot.TestPlot(methodName='runTest')[source]

Bases: tests.basetest.Basetest

test the Plot helper class

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

testPlot()[source]

test a plot based on a Counter

tests.test_Tabulate module

Created on 2021-06-13

@author: wf

class tests.test_Tabulate.TestTabulate(methodName='runTest')[source]

Bases: tests.basetest.Basetest

test tabulate support/compatibility

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

testIssue24_IntegrateTabulate()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/24

test https://pypi.org/project/tabulate/ support

tests.test_csv module

class tests.test_csv.TestCSV(methodName='runTest')[source]

Bases: tests.basetest.Basetest

Tests functionalities for the conversion between csv and list od dicts (LoD)

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

setUp()[source]

setUp test environment

tearDown() → None[source]

Hook method for deconstructing the test fixture after testing it.

testCsvFromJSONAble()[source]

tests generation of csv from list of JSONAble object

testCsvFromJSONAbleExcludeFields()[source]

tests generation of csv from list of JSONAble object with excluding specific fields (negative list)

testCsvFromJSONAbleIncludeFields()[source]

tests generation of csv from list of JSONAble object with including only specified fields (positive list)

testRoyals()[source]

test conversion of royals

test_from_csv()[source]

tests if the csv is correctly parsed to an LoD

test_from_csv_without_header()[source]

tests if csv string without embedded headers is parsed correctly

test_restore_from_csvfile()[source]

tests if the lod is correctly restored from csv file

test_round_trip()[source]

tests the csv round trip: dict -> csv -> dict Note: the inital dict has missing values it is expected that the final dict has the missing keys with None as value

test_store_to_csvfile()[source]

tests if LoD is correctly stored as csv file

test_to_csv()[source]

tests if LoD is correctly converted to csv str

test_to_csv_delimiter_in_value()[source]

tests if delimiter in dict value will not result in incorrect values

test_to_csv_incomplete_dicts()[source]

tests if the LoD is correctly converted to csv even if some dicts are incomplete Note: incomplete dicts can lead to changes of the column orders of the csv string

tests.test_lod module

Created on 2021-06-11

@author: wf

class tests.test_lod.TestLOD(methodName='runTest')[source]

Bases: tests.basetest.Basetest

test list of dicts base functionality

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

checkHandleListTypeResult(lod, expectedLen, expected)[source]

check the result of the handleListType function

Parameters:
  • lod (list) – the list of dicts to check
  • expectedLen (int) – the expected Length
  • expected (str) – the expected entry for the München,Munich Q1524 record with a list
testGetFields()[source]

tests field extraction from list of JSONAble objects and LoD

testGetLookupIssue31And32()[source]

test for https://github.com/WolfgangFahl/pyLoDStorage/issues/31 test for https://github.com/WolfgangFahl/pyLoDStorage/issues/32

testListHandlingIssue33()[source]

test for handling list

testListIntersect()[source]

test a list intersection

tests.test_queries module

Created on 2021-01-29

@author: wf

class tests.test_queries.TestEndpoints(methodName='runTest')[source]

Bases: tests.basetest.Basetest

tests Endpoint

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

testEndpoints()[source]

tests getting and rawQuerying Endpoints

class tests.test_queries.TestQueries(methodName='runTest')[source]

Bases: tests.basetest.Basetest

Test query handling

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

captureQueryMain(args)[source]

run queryMain and capture stdout

Parameters:args (list) – command line arguments
Returns:the stdout content of the command line call
Return type:str
testCommandLineUsage()[source]

test the command line usage

testIssue111()[source]

https://github.com/WolfgangFahl/pyLoDStorage/issues/111 add basicauth support for endpoints

testIssue115Limit()[source]

test the limit argument

testIssue61()[source]

tests different query path

see https://github.com/WolfgangFahl/pyLoDStorage/issues/61

testIssue69showEndpoints()[source]

test the listEndpoints option

https://github.com/WolfgangFahl/pyLoDStorage/issues/69

testIssue70showQuery()[source]

test the showQuery option

https://github.com/WolfgangFahl/pyLoDStorage/issues/70

testIssue73Formatting()[source]

test formatting

testIssue73ReadFormats()[source]

test reading the valueFormatters

testIssue89()[source]

test fix TypeError(‘Object of type datetime is not JSON serializable’) #89

testQueryCommandLine()[source]

test the sparql query command line

testQueryDocumentation()[source]

test QueryDocumentation

testQueryEndpoints()[source]

tests the sparql endpoint commandline endpoint selection

testSQLQueries()[source]

see https://github.com/WolfgangFahl/pyLoDStorage/issues/19

testSparqlQueries()[source]

test SPARQL queries

testUnicode2LatexWorkaround()[source]

test the uniCode2Latex conversion workaround

Module contents