[go: nahoru, domu]

Skip to content

Karma Testing Infrastructure

szeke edited this page Oct 14, 2014 · 2 revisions

A Nice Back-End Testing Framework

It would be nice to have a testing framework that makes it very easy to generate command histories for testing. Often, bugs crop up because people create complicated command histories where they add and remove things, eventually confusing Karma.

Suppose we had a nice Python binding for all Karma commands and it was possible to write code as the following (the code below is Pythonish, possibly with many syntax errors because Pedro doesn't know Python well).

# Get ontology classes and properties I want to use in a testing scenario
a = getClass("http://...") 
b = getClass("http://...")
p = getProperty("http://...")
q = getProperty("http://...")

# Create a worksheet from JSON.
json = [...]
w = createWorksheet(json)

# Create semantic type by URI
s1 = w.setSemanticType('x', a)

# Create semantic type by class and property
s2 = w.setSemanticType('y', b, p)

# Add some links
n1 = w.addIncoming(s1, c, q)
# I can use a node where I put classes
w.addIncoming(s2, n1, r) 

# Publish my model into a variable
model = w.publishModel()

# Generate RDF and test the output
rdf = generateRDF()
testMyRdf1(rdf)

# Let's test in the same JSON after reloading the model
w2 = createWorksheet(json)
w2.applyModel(model)
testMyRdf1(w2.generateRdf())

# Let's test that the model works when I reload it on a modeled worksheet
w3 = createWorksheet(json)
w.setSemanticType('x', c) # Different semantic type than I had before
w3.applyModel(model, true) # true means reset the model
testMyRdf1(w3.generateRdf())

# My Rdf test functions
def testMyRdf1(rdf):
  rdf.numTriples(20) # Test that the RDF has 20 triples
  rdf.hasTriple('a subject', 'a predicate', 'a object')

def testMyRdf2(rdf):
  rdf.numTriples(33) 
  rdf.hasTriple('a subject', 'a predicate', 'a object')

It would be fairly easy to write tests that do strange things that users do such as adding semantic types, changing their mind, etc.:

w = createWorksheet(json)
w.setSemanticType('x', a)
s1 = w.setSemanticType('x', b)
# Later in the RDF we test that b took effect

If someone reports a bug in a karma zipped folder we could do the following:

loadKarmaZip('zip-file')
w = createWorksheet('provided-file')
w.applyModel('provided-model')

# Testing something about the model
s1 = w.getSemanticType('x', 'some class') # Gets expected semantic type
assert(s1) # I invented to mean that we expect non null
n1 = w.getIncoming(s1, 'another class', 'some property')
assert(n1)

# Testing something about the JSON it generates
json = n1.generateJson()
json[0].hasValue('abc', 'some value') # test something about the generated JSON
rdf = w.generateRdf()

We can create Python bindings for all the other constructs. We could use Groovy or Scala or something else if it makes it easier to interface with our current code. To test the transformation functions we write a getJson method for worksheets that returns the raw worksheet in JSON, and then use JSON testing functions.

Clone this wiki locally