def test_init_LocationPath_current(self): lp = diffjson.LocationPath([ diffjson.LocationStep(diffjson.NodenameRoot()), diffjson.LocationStep(diffjson.NodenameKey('key01')), diffjson.LocationStep(diffjson.NodenameKey('key02')), ]) expected = '/' assert str(lp.current()) == expected
def test_init_LocationPath_branch(self): lp = diffjson.LocationPath([ diffjson.LocationStep(diffjson.NodenameRoot()), diffjson.LocationStep(diffjson.NodenameKey('key01')), diffjson.LocationStep(diffjson.NodenameKey('key02')), ]) expected = 'key01/key02' assert str(lp.branch()) == expected
def test_init_LocationStepWithPredicates(self): plp = diffjson.LocationPath( [diffjson.LocationStep(diffjson.NodenameKey('key'))]) p = diffjson.Predicate(plp, 'predicate') ps = diffjson.Predicates([p]) l = diffjson.LocationStep(diffjson.NodenameRoot(), ps) expected = '/[key=predicate]' assert str(l) == expected
def test_parse_simple01(self): """ Parser must parse input string and output appropriate LocationPath instance. """ expected = diffjson.LocationPath([ diffjson.LocationStep(diffjson.NodenameRoot()), diffjson.LocationStep(diffjson.NodenameKey('branch01')), diffjson.LocationStep(diffjson.NodenameKey('b01-01')), ]) pathstring = '/branch01/b01-01' p = diffjson.parse(pathstring) assert p == expected assert str(p) == pathstring
def test_parse_with_self(self): """ Parser with Self. """ expected = diffjson.LocationPath([ diffjson.LocationStep(diffjson.NodenameRoot()), diffjson.LocationStep(diffjson.NodenameKey('branch01')), diffjson.LocationStep(diffjson.NodenameSelf()), diffjson.LocationStep(diffjson.NodenameKey('b01-01')), ]) pathstring = '/branch01/./b01-01' p = diffjson.parse(pathstring) assert p == expected assert str(p) == pathstring
def test_parse_with_decendant(self): """ Parser with Descendant. """ expected = diffjson.LocationPath([ diffjson.LocationStep(diffjson.NodenameRoot()), diffjson.LocationStep(diffjson.NodenameKey('branch01')), diffjson.LocationStep(diffjson.NodenameDescendant()), diffjson.LocationStep(diffjson.NodenameKey('branch01-01-01')), ]) pathstring = '/branch01//branch01-01-01' p = diffjson.parse(pathstring) assert p == expected assert str(p) == pathstring
def test_init_Predicate(self): plp = diffjson.LocationPath( [diffjson.LocationStep(diffjson.NodenameKey('key'))]) p = diffjson.Predicate(plp, 'predicate') expected = 'key=predicate' assert str(p) == expected
def test_init_LocationPath(self): lp = diffjson.LocationPath( [diffjson.LocationStep(diffjson.NodenameRoot())]) expected = '/' assert str(lp) == expected