Diff of /doc/source/knowledge_bases/special.txt [5cabfd] .. [4dca5a] Maximize Restore

  Switch to unified view

a/doc/source/knowledge_bases/special.txt b/doc/source/knowledge_bases/special.txt
...
...
178
Succeeds if the command returns a zero exit status.  Fails otherwise.  Any
178
Succeeds if the command returns a zero exit status.  Fails otherwise.  Any
179
output from the command to stdout or stderr is unavailable.
179
output from the command to stdout or stderr is unavailable.
180
180
181
    >>> from pyke import knowledge_engine
181
    >>> from pyke import knowledge_engine
182
    >>> engine = knowledge_engine.engine()
182
    >>> engine = knowledge_engine.engine()
183
    >>> engine.prove_1('special', 'check_command', (('true',),), 0)
183
    >>> engine.prove_1_goal('special.check_command((true))')
184
    ((), None)
184
    ({}, None)
185
    >>> engine.prove_1('special', 'check_command', (('false',),), 0)
185
    >>> engine.prove_1_goal('special.check_command((false))')
186
    Traceback (most recent call last):
186
    Traceback (most recent call last):
187
        ...
187
        ...
188
    pyke.knowledge_engine.CanNotProve: Can not prove special.check_command((false))
188
    pyke.knowledge_engine.CanNotProve: Can not prove special.check_command((false))
189
189
190
Command
190
Command
...
...
203
exit status.
203
exit status.
204
204
205
    >>> from __future__ import with_statement
205
    >>> from __future__ import with_statement
206
    >>> from pyke import pattern, contexts
206
    >>> from pyke import pattern, contexts
207
    >>> def run_command(entity, command, cwd=None, stdin=None):
207
    >>> def run_command(entity, command, cwd=None, stdin=None):
208
    ...     my_context = contexts.simple_context()
208
    ...     with engine.prove_goal(
209
    ...     output = contexts.variable('output')
209
    ...            'special.%s($output, $command, $cwd, $stdin)' % entity,
210
    ...     with engine.prove('special', entity, my_context,
210
    ...            command=command,
211
    ...                       (output,
211
    ...            cwd=cwd,
212
    ...                        pattern.pattern_literal(command),
212
    ...            stdin=stdin) \
213
    ...                        pattern.pattern_literal(cwd),
214
    ...                        pattern.pattern_literal(stdin))) \
215
    ...       as gen:
213
    ...       as gen:
216
    ...         for no_plan in gen:
214
    ...         for vars, no_plan in gen:
217
    ...             print(output.as_data(my_context))
215
    ...             print(vars['output'])
218
    >>> run_command('command', ('echo', 'hi', 'mom'))
216
    >>> run_command('command', ('echo', 'hi', 'mom'))
219
    ('hi mom',)
217
    ('hi mom',)
220
    >>> run_command('command', ('ls',))   # doctest: +NORMALIZE_WHITESPACE
218
    >>> run_command('command', ('ls',))   # doctest: +NORMALIZE_WHITESPACE
221
    ('fact_bases.txt', 'index.txt', 'links', 'question_bases.txt',
219
    ('fact_bases.txt', 'index.txt', 'links', 'question_bases.txt',
222
     'rule_bases.txt', 'special.txt')
220
     'rule_bases.txt', 'special.txt')