Skip to content

Commit

Permalink
fix jq pub
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasheinrich committed Jan 12, 2018
1 parent f239e85 commit e175144
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packtivity/handlers/publisher_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def fromyaml_pub_handler(publisher,parameters,state):

@publisher('fromparjq-pub')
def fromparjq_pub(publisher,parameters,state):
inputjson = parameters
result = parameters.jq(publisher['script'])
for path,value in result.leafs():
## if the leaf value is not stringy or no state to operate on, ignore
Expand All @@ -78,9 +77,10 @@ def fromparjq_pub(publisher,parameters,state):
globresult = glob2.glob(searchval)
if globresult:
value = globresult
path.set(result,value)
result.replace(path, value)
return result


@publisher('fromglob-pub')
def glob_pub_handler(publisher,parameters,state):
workdir = state.readwrite[0]
Expand Down
2 changes: 2 additions & 0 deletions packtivity/typedleafs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def _load_from_string(self,jsonstring, typed = True, idleafs = False):
def _dump_to_string(self,data):
return json.dumps(data, default = self._leafmodel.dumper)

def replace(self, path, value):
path.set(self.json(), value)

### representation methods
def json(self):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_publishers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from packtivity.handlers.publisher_handlers import handlers
from packtivity.typedleafs import TypedLeafs

def test_parpub(tmpdir,basic_localfs_state):
pub = {
Expand Down Expand Up @@ -79,6 +80,7 @@ def test_fromparjq_pub(tmpdir,basic_localfs_state):
pars = {
'mypar': 'myvalue'
}
pars = TypedLeafs(pars)
pubbed = handlers['fromparjq-pub']['default'](pub,pars,basic_localfs_state)
filelist = map(str,[tmpdir.join('hello_myvalue_1.txt'),tmpdir.join('hello_myvalue_2.txt')])
assert set(pubbed['hello']) == set(filelist)
Expand All @@ -96,8 +98,10 @@ def test_fromparjq_pub_relative(tmpdir,basic_localfs_state):
pars = {
'mypar': 'myvalue'
}
pars = TypedLeafs(pars)
pubbed = handlers['fromparjq-pub']['default'](pub,pars,basic_localfs_state)
filelist = map(str,[tmpdir.join('hello_myvalue_1.txt'),tmpdir.join('hello_myvalue_2.txt')])
assert set(pubbed['hello']) == set(filelist)


def test_glob_pub(tmpdir,basic_localfs_state):
Expand Down

0 comments on commit e175144

Please sign in to comment.