<commit_before>#  Copyright 2008 Nokia Siemens Networks Oyj
#  
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.


import os.path
import unittest

from mabot.model import io
from mabot.model.model import DATA_MODIFIED


DATA = os.path.join(os.path.dirname(__file__), 'data', 'testcases.xml')


class TestSettingStatusAndMessage(unittest.TestCase):
    
    def setUp(self):
        self.io = io.IO()
        self.suite = self.io.load_data(DATA)
        
    def tearDown(self):
        DATA_MODIFIED.saved()

    def test_pass_all_with_suite(self):
        self.suite.set_all('PASS')
        self._all_status_should_be(self.suite, 'PASS')
        expected_messages = ['Passing', '', 'Failing', 'Not Executed!']
        self._messages_should_be(self.suite.tests, expected_messages)
        expected_messages[3] = ''
        self._messages_should_be(self.suite.tests[0].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[1].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[2].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[3].keywords, expected_messages)
        

    def test_fail_all_with_suite(self):
        self.suite.set_all('FAIL', 'Suite failure')
        self._all_status_should_be(self.suite, 'FAIL')
        expected_messages = ['Passing', '', 'Failing', 'Suite failure']
        self._messages_should_be(self.suite.tests, expected_messages)
        expected_messages[1] = 'Suite failure'
        self._messages_should_be(self.suite.tests[0].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[1].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[2].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[3].keywords, expected_messages)

    def test_fail_all_with_test(self):
        test = self.suite.tests[0]
        test.set_all('PASS')
        self._all_status_should_be(test, 'PASS')
        expected_messages = ['Passing', '', 'Failing', '']
        self._messages_should_be(test.keywords, expected_messages)

    def test_fail_all_with_test(self):
        test = self.suite.tests[0]
        test.set_all('FAIL', 'Test failure')
        self._all_status_should_be(test, 'FAIL')
        expected_messages = ['Passing', 'Test failure', 'Failing', 'Test failure']
        self._messages_should_be(test.keywords, expected_messages)

    def test_suite_is_informed(self):
        self.suite.tests[2].set_all('PASS')
        self.suite.tests[3].set_all('PASS')
        self.suite.tests[4].set_all('PASS')
        self.assertEqual(self.suite.status, 'PASS')

    def test_pass_all_with_keyword(self):
        test = self.suite.tests[4]
        test.set_all('FAIL', 'Test failure')
        self._all_status_should_be(test, 'FAIL')
        self.assertEquals(test.keywords[0].keywords[0].status, 'FAIL')
        test.set_all('PASS', 'Test failure')
        self._all_status_should_be(test, 'PASS')
        self.assertEquals(test.keywords[0].status, 'PASS')
        self.assertEquals(test.keywords[0].keywords[0].status, 'PASS')

    def test_change_test_status_to_fail(self):
        test = self.suite.tests[0]
        test.update_status_and_message('FAIL', 'Failure')<commit_msg>Tests for issue 33. When test or keyword which message is not default is set to failed with set_all, the fail message is added to the beginning of the original message.<commit_after>#  Copyright 2008 Nokia Siemens Networks Oyj
#  
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#  
#      http://www.apache.org/licenses/LICENSE-2.0
#  
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.


import os.path
import unittest

from mabot.model import io
from mabot.model.model import DATA_MODIFIED


DATA = os.path.join(os.path.dirname(__file__), 'data', 'testcases.xml')


class TestSettingStatusAndMessage(unittest.TestCase):
    
    def setUp(self):
        self.io = io.IO()
        self.suite = self.io.load_data(DATA)
        
    def tearDown(self):
        DATA_MODIFIED.saved()

    def test_pass_all_with_suite(self):
        self.suite.set_all('PASS')
        self._all_status_should_be(self.suite, 'PASS')
        expected_messages = ['Passing', '', 'Failing', 'Not Executed!']
        self._messages_should_be(self.suite.tests, expected_messages)
        expected_messages[3] = ''
        self._messages_should_be(self.suite.tests[0].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[1].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[2].keywords, expected_messages)
        self._messages_should_be(self.suite.tests[3].keywords, expected_messages)
        

    def test_fail_all_with_suite(self):
        self.suite.set_all('FAIL', 'Suite failure')
        self._all_status_should_be(self.suite, 'FAIL')
        expected_messages = ['Suite failure\nPassing', 'Suite failure', 
                             'Suite failure\nFailing', 'Suite failure']
        self._messages_should_be(self.suite.tests, expected_messages)
        for i in range(0, 4):
            self._messages_should_be(self.suite.tests[i].keywords, 
                                     expected_messages)

    def test_fail_all_with_test(self):
        test = self.suite.tests[0]
        test.set_all('PASS')
        self._all_status_should_be(test, 'PASS')
        expected_messages = ['Passing', '', 'Failing', '']
        self._messages_should_be(test.keywords, expected_messages)

    def test_fail_all_with_test(self):
        test = self.suite.tests[0]
        test.set_all('FAIL', 'Test failure')
        self._all_status_should_be(test, 'FAIL')
        expected_messages = ['Test failure\nPassing', 'Test failure', 
                             'Test failure\nFailing', 'Test failure']
        self._messages_should_be(test.keywords, expected_messages)

    def test_suite_is_informed(self):
        self.suite.tests[2].set_all('PASS')
        self.suite.tests[3].set_all('PASS')
        self.suite.tests[4].set_all('PASS')
        self.assertEqual(self.suite.status, 'PASS')

    def test_pass_all_with_keyword(self):
        test = self.suite.tests[4]
        test.set_all('FAIL', 'Test failure')
        self._all_status_should_be(test, 'FAIL')
        self.assertEquals(test.keywords[0].keywords[0].status, 'FAIL')
        test.set_all('PASS', 'Test failure')
        self._all_status_should_be(test, 'PASS')
        self.assertEquals(test.keywords[0].status, 'PASS')
        self.assertEquals(test.keywords[0].keywords[0].status, 'PASS')

    def test_change_test_status_to_fail(self):
        test = self.suite.tests[0]
        test.update_status_and_message('FAIL', 'Failure')
{'fraction_non_alphanumeric': 0.11494404213298222, 'fraction_numerical': 0.007768268597761686, 'mean_word_length': 3.3530085959885385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5995666', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2282, 'n_words': 473}