Esempio n. 1
0
 def setUp(self):
     setup_bond_self_test(self, ())
Esempio n. 2
0
    def setUp(self):
        self.testing_observation_dir = '/tmp/bondObservations Dir'  # Intentionally put a space in the path
        self.reference_file = os.path.join(self.testing_observation_dir, 'reference.json')

        self.reference_file_content = """
[
{
   "__spy_point__" : "point 1",
   val" : 12345
}
]
"""
        self.reference_file_content_lines = map(lambda s: s + '\n',
                                                self.reference_file_content.split('\n')[0:-1])

        setup_bond_self_test(self)

        def format_diff_join_lists(obs):
            obs['current_lines'] = ''.join(obs['current_lines'])
            obs['reference_lines'] = ''.join(obs['reference_lines'])

        bond.deploy_agent('bond_reconcile._compute_diff',
                          formatter=format_diff_join_lists,
                          result=bond.AGENT_RESULT_CONTINUE)

        bond.deploy_agent('bond_reconcile._random_string', result='random')

        self.console_reply = []  # List of strings to reply when we try to read from console
        bond.deploy_agent('bond_reconcile._get_user_input',
                          result=lambda obs: self.console_reply.pop(0) if self.console_reply
                          else bond.AGENT_RESULT_CONTINUE)

        self.kdiff3_result = 0

        def mock_kdiff3(obs):
            "Mock call to kdiff3"
            if not self.during_test:
                return bond.AGENT_RESULT_CONTINUE

            if self.kdiff3_result == 0:
                # Success, create the merged file
                # First, get the file name from the command line
                m = re.search(r'-o\s*"([^"]+)"', obs['cmd'])
                if m:
                    with open(m.group(1), 'w') as f:
                        f.write("The merge result")

            return self.kdiff3_result

        bond.deploy_agent('bond_reconcile._invoke_command',
                          cmd__startswith='kdiff3 ',
                          result=mock_kdiff3)

        # A special formatter for the printing of diffs
        def _print_formatter(obs):
            # We want to observe each line individually
            res = []
            for l in obs['what'].split('\n'):
                res.append(l)
            obs['what'] = res
        bond.deploy_agent('bond_reconcile._print',
                          what__contains='@@',
                          formatter=_print_formatter)