def test_get_line_valid(self):
        # Setup: Create a script file with a selection of test text
        sf = ScriptFile('uri', 'abc\r\ndef\r\nghij\r\nklm', None)

        # If: I ask for a valid line
        # Then: I should get that line w/o new lines
        self.assertEqual(sf.get_line(0), 'abc')
        self.assertEqual(sf.get_line(1), 'def')
        self.assertEqual(sf.get_line(3), 'klm')
    def test_set_file_contents(self):
        # If: I set the contents of a script file
        sf = ScriptFile('uri', '', None)
        sf._set_file_contents('line 1\r\n  line 2\n  line 3  ')

        # Then: I should get the expected output lines
        expected_output = ['line 1', '  line 2', '  line 3  ']
        self.assertListEqual(sf.file_lines, expected_output)
        self.assertListEqual(sf._file_lines, expected_output)
    def test_init_missing_params(self):
        for value in [None, '', '  \t\t\r\n\r\n']:
            with self.assertRaises(ValueError):
                # If: I create a script file while missing a file_uri
                # Then: I expect it to raise an exception
                ScriptFile(value, 'buffer', None)

        with self.assertRaises(ValueError):
            # If: I create a script file while missing a initial buffer
            ScriptFile('file_uri', None, None)
    def _get_test_workspace(
            script_file: bool = True
    ) -> Tuple[Workspace, Optional[ScriptFile]]:
        w: Workspace = Workspace()
        sf: Optional[ScriptFile] = None
        if script_file:
            sf = ScriptFile('file_path', 'client_path', '')
            w._workspace_files['file_path'] = sf

        return w, sf
    def test_init_most_params(self):
        # If: I create a script file with all the parameters provided
        uri = 'file_uri'
        buffer = 'buffer'
        sf = ScriptFile(uri, buffer, None)

        # Then: The state should be setup with all the provided values
        self.assertEqual(sf._file_uri, uri)
        self.assertEqual(sf.file_uri, uri)
        self.assertIsNone(sf._file_path)
        self.assertIsNone(sf.file_path)
        self.assertListEqual(sf._file_lines, [buffer])
        self.assertListEqual(sf.file_lines, [buffer])
    def _get_mock_script_file() -> ScriptFile:
        sf: ScriptFile = ScriptFile('path', 'path', '')
        sf.apply_change = MagicMock()

        return sf
 def _get_test_script_file() -> ScriptFile:
     return ScriptFile('uri', 'abc\r\ndef\r\nghij\r\nklm', None)