Beispiel #1
0
    def test_modify_strip(self):
        t = SimpleText('')

        self.assertEqual(t.text, '')

        t.text = '     \t\nfoo \n \t  '
        self.assertEqual(t.text, 'foo')
Beispiel #2
0
    def test_edit_specific_file(self, s):
        text = SimpleText('foo')

        with tempfile.NamedTemporaryFile(mode='w+t') as tmp:

            textedit = TextEditor(text, filename=tmp.name)

            with textedit as t:

                t._file.seek(0, 2)
                t._file.write(' bar')
                t._file.seek(0)
                t._file.flush()
                os.fsync(t._file.fileno())
                t.run()

                self.assertEqual(t.result().text, 'foo bar')

            self.assertEqual(t._file, None)

            tmp.seek(0)
            self.assertEqual(tmp.read(), 'foo bar')

            tmp.close()

        with tempfile.TemporaryDirectory() as tempdir:
            textedit.save(tempdir, 't.txt')

            with open(os.path.join(tempdir, 't.txt')) as fp:
                self.assertEqual(fp.read(), 'foo bar')
Beispiel #3
0
    def test_basic(self, s):
        text = SimpleText('foo bar')
        textedit = TextEditor(text)

        with textedit as t:
            t._file.seek(0, 2)
            t._file.write(' baz')
            t._file.seek(0)
            t.run()
            s.assert_called_with([t._editor, t._file.name])
            result = t.result()

            self.assertEqual(result.text, 'foo bar baz')
Beispiel #4
0
    def test_multirun(self, s):
        text = SimpleText('foo bar')

        textedit = TextEditor(text)
        with self.assertRaises(TextEditorException):
            textedit.run()

        with textedit as t:
            t.run()
            t.run()

            self.assertEqual(t.result().text, 'foo bar')

        self.assertEqual(textedit.result().text, 'foo bar')
Beispiel #5
0
    def test_creation(self):
        t = SimpleText('foo bar')

        self.assertEqual(t.text, 'foo bar')
Beispiel #6
0
    def test_reload(self):
        t = SimpleText('foo')

        t.reload('\tbar\t')

        self.assertEqual(t.text, 'bar')
Beispiel #7
0
    def test_decode(self):
        t = SimpleText.decode('   \t\n  foo   ')

        self.assertEqual(t.text, 'foo')
Beispiel #8
0
    def test_decode_encoded(self):
        t = SimpleText('  \n foo bar \n ')

        t2 = SimpleText.decode(t.encode())

        self.assertEqual(t.text, t2.text)
Beispiel #9
0
    def test_encode(self):
        t = SimpleText('text')

        self.assertEqual(t.encode(), 'text')
Beispiel #10
0
    def test_strip(self):
        t = SimpleText('     \t\nfoo\t\n    ')

        self.assertEqual(t.text, 'foo')