<commit_before># fMBT, free Model Based Testing tool
# Copyright (c) 2011, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU Lesser General Public License,
# version 2.1, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

import pexpect
import subprocess
import time
import types
import os
import signal

FMBT_BINARY = '../../src/fmbt'

# Fmbt instances started during tests write their log to FMBT_LOGFILE
FMBT_LOGFILE = '/tmp/fmbt.test.interactivemode.subfmbt.log'

# If an assertion fails, compared value is most often saved to the
# debug file
TEST_DEBUGFILE ='/tmp/fmbt.test.interactivemode.debug'

# Writes from started fmbt instances are redirected to FMBT_STDERRFILE
FMBT_STDERRFILE = '/tmp/fmbt.test.interactivemode.subfmbt.stderr'

PROMPT = 'fMBT> '

process_response_time = lambda: time.sleep(0.5)
ui_response_time = lambda: time.sleep(0.1)
all_actions = []

def _debug(x):
    file(TEST_DEBUGFILE,'a').write(str(x) + '\n\n')
    return x

def _output2list(ttyoutput):
    s = ttyoutput.replace('\r', '')
    return s.split('\n')

def _run_command(cmd, delay_before_output = ui_response_time):
    fmbt.write(cmd + '\n')
    delay_before_output()
    output = fmbt_output()[1:]
    _debug("command: '%s'\nresult:%s\n" % (cmd, output))
    return output

# Fmbt-i.mrules expects functions corresponding to actions to return
# True when executed successfully. On error they should return
# something - or throw an exception - that helps debugging the error.

def iStartGoodFmbt():
    global fmbt
    global fmbt_output
    fmbt = pexpect.spawn(FMBT_BINARY + ' -L' + FMBT_LOGFILE
                         + ' -i test.conf')
    def output_reader():
        s = ""
        while 1:
            try: s += fmbt.read_nonblocking(4096, 0.5)<commit_msg>tests: even slower and more reliable interactive mode test<commit_after># fMBT, free Model Based Testing tool
# Copyright (c) 2011, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU Lesser General Public License,
# version 2.1, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

import pexpect
import subprocess
import time
import types
import os
import signal

FMBT_BINARY = '../../src/fmbt'

# Fmbt instances started during tests write their log to FMBT_LOGFILE
FMBT_LOGFILE = '/tmp/fmbt.test.interactivemode.subfmbt.log'

# If an assertion fails, compared value is most often saved to the
# debug file
TEST_DEBUGFILE ='/tmp/fmbt.test.interactivemode.debug'

# Writes from started fmbt instances are redirected to FMBT_STDERRFILE
FMBT_STDERRFILE = '/tmp/fmbt.test.interactivemode.subfmbt.stderr'

PROMPT = 'fMBT> '

process_response_time = lambda: time.sleep(0.5)
ui_response_time = lambda: time.sleep(0.1)
all_actions = []

def _debug(x):
    file(TEST_DEBUGFILE,'a').write(str(x) + '\n\n')
    return x

def _output2list(ttyoutput):
    s = ttyoutput.replace('\r', '')
    return s.split('\n')

def _run_command(cmd, delay_before_output = ui_response_time):
    fmbt.write(cmd + '\n')
    delay_before_output()
    output = fmbt_output()[1:]
    _debug("command: '%s'\nresult:%s\n" % (cmd, output))
    return output

# Fmbt-i.mrules expects functions corresponding to actions to return
# True when executed successfully. On error they should return
# something - or throw an exception - that helps debugging the error.

def iStartGoodFmbt():
    global fmbt
    global fmbt_output
    fmbt = pexpect.spawn(FMBT_BINARY + ' -L' + FMBT_LOGFILE
                         + ' -i test.conf')
    def output_reader():
        s = ""
        while 1:
            try: s += fmbt.read_nonblocking(4096, 2.0)
{'fraction_non_alphanumeric': 0.09352827348957214, 'fraction_numerical': 0.012900451515803053, 'mean_word_length': 3.781089414182939, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7533526', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1456, 'n_words': 517}