Changeset - 168262618f2d
[Not reviewed]
default
0 3 2
Drew Perttula - 9 years ago 2016-06-05 22:41:04
drewp@bigasterisk.com
new test_js target for testing SyncedGraph
Ignore-this: fda788c5e8f5cf1190eb383e1cf2b1ad
5 files changed with 50 insertions and 0 deletions:
0 comments (0 inline, 0 general)
light9/web/graph.coffee
Show inline comments
 
log = console.log
 

	
 
# Patch is {addQuads: <quads>, delQuads: <quads>}
 
# <quads> is [{subject: s, ...}, ...]
 

	
 
# for mocha
 
if require?
 
  `window = {}`
 
  `N3 = require('./lib/N3.js-1d2d975c10ad3252d38393c3ea97b36fd3ab986a/N3.js')`
 
  `RdfDbClient = require('./rdfdbclient.js').RdfDbClient`
 
  module.exports = window
 

	
 
# (sloppily shared to rdfdbclient.coffee too)
 
window.patchSizeSummary = (patch) ->
 
  '-' + patch.delQuads.length + ' +' + patch.addQuads.length
 

	
 
# partial port of autodepgraphapi.py
 
class GraphWatchers
 
  constructor: ->
 
    @handlersSp = {} # {s: {p: [handlers]}}
 
  subscribe: (s, p, o, onChange) -> # return subscription handle
 
    if o? then throw Error('not implemented')
 
    if not @handlersSp[s]
 
      @handlersSp[s] = {}
 
@@ -51,24 +58,25 @@ class window.SyncedGraph
 
  # rdfdb. Meant to hide the choice of RDF lib, so we can change it
 
  # later.
 
  # 
 
  # Note that _applyPatch is the only method to write to the graph, so
 
  # it can fire subscriptions.
 

	
 
  constructor: (@patchSenderUrl, @prefixes, @setStatus) ->
 
    # patchSenderUrl is the /syncedGraph path of an rdfdb server.
 
    # prefixes can be used in Uri(curie) calls.
 
    @_watchers = new GraphWatchers()
 
    @clearGraph()
 

	
 
    if @patchSenderUrl
 
    @_client = new RdfDbClient(@patchSenderUrl, @clearGraph.bind(@),
 
                               @_applyPatch.bind(@), @setStatus)
 
    
 
  clearGraph: ->
 
    log('SyncedGraph clear')
 
    if @graph?
 
      @_applyPatch({addQuads: [], delQuads: @graph.find()})
 

	
 
    # if we had a Store already, this lets N3.Store free all its indices/etc
 
    @graph = N3.Store()
 
    @_addPrefixes(@prefixes)
 
    
light9/web/graph_test.coffee
Show inline comments
 
new file 100644
 
assert = require('chai').assert
 
SyncedGraph = require('./graph.js').SyncedGraph
 

	
 
describe 'SyncedGraph', ->
 
  describe 'constructor', ->
 
    it 'should successfully make an empty graph without connecting to rdfdb', ->
 
      g = new SyncedGraph()
 
      g.quads()
 
      assert.equal(g.quads().length, 0)
 

	
light9/web/rdfdbclient.coffee
Show inline comments
 
log = console.log
 

	
 
# for mocha
 
if require?
 
  `window = {}`
 
  `N3 = require('./lib/N3.js-1d2d975c10ad3252d38393c3ea97b36fd3ab986a/N3.js')`
 
  module.exports = window
 

	
 

	
 
toJsonPatch = (jsPatch, cb) ->
 
  out = {patch: {adds: '', deletes: ''}}
 

	
 
  writeDels = (cb) ->
 
    writer = N3.Writer({ format: 'N-Quads' })
 
    writer.addTriples(jsPatch.delQuads)
 
    writer.end((err, result) ->
 
      out.patch.deletes = result
 
      cb())
 

	
 
  writeAdds = (cb) ->
makefile
Show inline comments
 
NOSEARGS="--no-path-adjustment light9.rdfdb.rdflibpatch light9.rdfdb.patch light9.effecteval.test_effect light9.collector"
 

	
 
tests:
 
	eval env/bin/nosetests -x $(NOSEARGS)
 

	
 
tests_watch:
 
	eval env/bin/nosetests --with-watcher $(NOSEARGS)
 

	
 

	
 
tests_coverage:
 
	eval env/bin/nosetests --with-coverage --cover-erase --cover-html --cover-html-dir=/tmp/light9-cov/  --cover-package=light9 --cover-branches $(NOSEARGS)
 

	
 
test_js_init:
 
	npm install
 

	
 
test_js:
 
	coffee -c light9/web/*.coffee
 
	node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --globals window,N3 light9/web/graph_test.coffee
 

	
 
# needed packages: python-gtk2 python-imaging
 

	
 
binexec:
 
	chmod a+x bin/*
 

	
 
install_python_deps: link_to_sys_packages
 
	env/bin/pip install twisted
 
	env/bin/pip install -U -r requirements.txt
 

	
 
DP=/usr/lib/python2.7/dist-packages
 
SP=env/lib/python2.7/site-packages
 

	
package.json
Show inline comments
 
new file 100644
 
{
 
  "name": "light9",
 
  "version": "1.0.0",
 
  "description": "Mini instructions:",
 
  "main": "index.js",
 
  "directories": {
 
    "test": "test"
 
  },
 
  "dependencies": {
 
    "chai": "^3.5.0",
 
    "mocha": "^2.5.3"
 
  },
 
  "devDependencies": {
 
    "mocha": "^2.5.3"
 
  },
 
  "scripts": {
 
    "test": "mocha"
 
  }
 
}
0 comments (0 inline, 0 general)