qspec
qspec copied to clipboard
'type error during .tst.restore when mocking data namespace within the global namespace
Mocking the data namespace (without the leading dot):
$ cat test.q
.tst.desc["Mocking"]{
should["support data namespace within the global namespace"]{
`myns.a mock `foo;
`myns.b mock `bar;
};
};
throws a 'type
error (namespaces with the leading dot work fine).
Exploring the environment reveals the root cause:
$ testq --fail-hard test.q
'type
[9] /home/dk/conda/q/lib/qspec-1.3.3/mock.q:28: .tst.restore:
/ Drop each fully qualified symbol from its respective namespace
if[count removeList;(.[;();_;]') . flip ((` sv -1 _;last) @\: ` vs) each removeList];
^
`.tst.removeList set ();
q.tst))`myns.a`myns.b in removeList
11b
q.tst))-3!myns
"()"
q.tst))get `..myns
| ::
a| `foo
b| `bar
q.tst))flip ((` sv -1 _;last) @\: ` vs) each `myns.a`myns.b
myns myns
a b
q.tst)).[`myns;();_;`a] / failure
'type
[11] .[`myns;();_;`a]
^
q.tst)).[`..myns;();_;`a] / success
`..myns
q.tst))get `..myns
| ::
b| `bar
Data namespaces (the ones without the leading dot) within removeList
are malformed. Instead of `ns.a`ns.b
, their fully-qualified name should be `..ns.a`..ns.b
.
The related code: https://github.com/nugend/qspec/blob/master/lib/mock.q#L9-L11