<commit_before>import unittest
import p4lib
from mock import Mock
from test_utils import change_stdout, test_options


SUBMIT_OUTPUT = """Change 1 created with 2 open file(s).
Submitting change 1.
Locking 2 files ...
add //depot/test_simple_submit.txt#1
edit //depot/test_other_submit.txt#3
Change 1 submitted.
//depot/test_simple_submit.txt#1 - refreshing
//depot/test_other_submit.txt#3 - refreshing
"""

TEMPORARY_FILENAME = "tempFile"
DESCRIPTION = "a changelist description"


class SubmitTestCase(unittest.TestCase):
    def setUp(self):
        p4lib._run = Mock(spec='p4lib._run', return_value=("", "", 0))
        p4lib._writeTemporaryForm = Mock(spec='p4lib._writeTemporaryForm',
                                         return_value=TEMPORARY_FILENAME)
        p4lib._removeTemporaryForm = Mock(spec='p4lib._removeTemporaryForm')

        change_stdout(SUBMIT_OUTPUT)
        self.p4 = p4lib.P4()

    def test_a_file(self):
        self.p4.where = Mock(spec='p4lib.where')
        self.p4.where.return_value = []

        self.p4.submit("/depot/test.txt", DESCRIPTION)

        p4lib._run.assert_called_with(['p4', 'submit',
                                       '-i', '<', 'tempFile'])

        self.p4.where.assert_called_with(['/depot/test.txt'])

    def test_a_file_list(self):
        FILELIST = ["/depot/test.txt", "/depot/test2.txt"]

        self.p4.where = Mock(spec='p4lib.where')
        self.p4.where.return_value = []

        self.p4.submit(FILELIST, DESCRIPTION)

        p4lib._run.assert_called_with(['p4', 'submit',
                                       '-i', '<', 'tempFile'])

        self.p4.where.assert_called_with(FILELIST)

    def test_default_file_list(self):
        self.p4.opened = Mock(spec='p4lib.opened')
        self.p4.opened.return_value = []

        self.p4.submit(files=[], description=DESCRIPTION)

        self.assertTrue(self.p4.opened.called)

    def test_a_changelist(self):
        self.p4.submit(change=1234)

        p4lib._run.assert_called_with(['p4', 'submit',
                                       '-c', '1234'])

    def test_has_forbidden_parameter_combinations(self):
        self.assertRaises(self.p4.submit, change=1234, description=DESCRIPTION)
        self.assertRaises(self.p4.submit, change=1234, files=[])

    def test_fills_results(self):
        result = self.p4.submit(change=1234)

        self.assertEqual("submitted", result["action"])
        self.assertEqual(1, result["change"])

        files = result["files"]
        self.assertEqual(2, len(files))

        expected_1 = {'action': 'add', 'rev': 1,
                      'depotFile': '//depot/test_simple_submit.txt'}
        expected_2 = {'action': 'edit', 'rev': 3,
                      'depotFile': '//depot/test_other_submit.txt'}

        self.assertEqual(expected_1, files[0])
        self.assertEqual(expected_2, files[1])

    def test_raw_result(self):
        raw_result = self.p4.submit(change=1234, _raw=True)

        self.assertIn('stdout', raw_result)
        self.assertIn('stderr', raw_result)
        self.assertIn('retval', raw_result)

        self.assertEqual(SUBMIT_OUTPUT, raw_result['stdout'])
<commit_msg>Fixed assertRaises in Submit tests<commit_after>import unittest
import p4lib
from mock import Mock
from test_utils import change_stdout, test_options


SUBMIT_OUTPUT = """Change 1 created with 2 open file(s).
Submitting change 1.
Locking 2 files ...
add //depot/test_simple_submit.txt#1
edit //depot/test_other_submit.txt#3
Change 1 submitted.
//depot/test_simple_submit.txt#1 - refreshing
//depot/test_other_submit.txt#3 - refreshing
"""

TEMPORARY_FILENAME = "tempFile"
DESCRIPTION = "a changelist description"


class SubmitTestCase(unittest.TestCase):
    def setUp(self):
        p4lib._run = Mock(spec='p4lib._run', return_value=("", "", 0))
        p4lib._writeTemporaryForm = Mock(spec='p4lib._writeTemporaryForm',
                                         return_value=TEMPORARY_FILENAME)
        p4lib._removeTemporaryForm = Mock(spec='p4lib._removeTemporaryForm')

        change_stdout(SUBMIT_OUTPUT)
        self.p4 = p4lib.P4()

    def test_a_file(self):
        self.p4.where = Mock(spec='p4lib.where')
        self.p4.where.return_value = []

        self.p4.submit("/depot/test.txt", DESCRIPTION)

        p4lib._run.assert_called_with(['p4', 'submit',
                                       '-i', '<', 'tempFile'])

        self.p4.where.assert_called_with(['/depot/test.txt'])

    def test_a_file_list(self):
        FILELIST = ["/depot/test.txt", "/depot/test2.txt"]

        self.p4.where = Mock(spec='p4lib.where')
        self.p4.where.return_value = []

        self.p4.submit(FILELIST, DESCRIPTION)

        p4lib._run.assert_called_with(['p4', 'submit',
                                       '-i', '<', 'tempFile'])

        self.p4.where.assert_called_with(FILELIST)

    def test_default_file_list(self):
        self.p4.opened = Mock(spec='p4lib.opened')
        self.p4.opened.return_value = []

        self.p4.submit(files=[], description=DESCRIPTION)

        self.assertTrue(self.p4.opened.called)

    def test_a_changelist(self):
        self.p4.submit(change=1234)

        p4lib._run.assert_called_with(['p4', 'submit',
                                       '-c', '1234'])

    def test_has_forbidden_parameter_combinations(self):
        self.assertRaises(p4lib.P4LibError, self.p4.submit, change=1234,
                          description=DESCRIPTION)
        self.assertRaises(p4lib.P4LibError, self.p4.submit, files=None,
                          description=DESCRIPTION)

    def test_fills_results(self):
        result = self.p4.submit(change=1234)

        self.assertEqual("submitted", result["action"])
        self.assertEqual(1, result["change"])

        files = result["files"]
        self.assertEqual(2, len(files))

        expected_1 = {'action': 'add', 'rev': 1,
                      'depotFile': '//depot/test_simple_submit.txt'}
        expected_2 = {'action': 'edit', 'rev': 3,
                      'depotFile': '//depot/test_other_submit.txt'}

        self.assertEqual(expected_1, files[0])
        self.assertEqual(expected_2, files[1])

    def test_raw_result(self):
        raw_result = self.p4.submit(change=1234, _raw=True)

        self.assertIn('stdout', raw_result)
        self.assertIn('stderr', raw_result)
        self.assertIn('retval', raw_result)

        self.assertEqual(SUBMIT_OUTPUT, raw_result['stdout'])

{'fraction_non_alphanumeric': 0.13514767280037113, 'fraction_numerical': 0.02505025514148755, 'mean_word_length': 2.607361963190184, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4101503', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2041, 'n_words': 312}