Exemple #1
0
    def test_insert_line_in_file_after_regex_inserts_line(self,
                                                          *args,
                                                          **kwargs):

        contents = '\n'.join(
            [
                'Here I am,',
                'on my bicycle',
                'cool, init?'
            ]
        )

        expected = '\r\n'.join(
            [
                'Here I am,',
                'on my bicycle',
                'Look mum, no hands',
                'cool, init?'
            ]
        )

        run('echo "%s" > /tmp/test' % contents)

        file.insert_line_in_file_after_regex('/tmp/test',
                                             'Look mum, no hands',
                                             '.*on.*bicycle')

        self.assertEqual(sudo('cat /tmp/test'), expected)
Exemple #2
0
    def test_insert_line_in_file_after_regex_raises_Exception_on_failure(
            self, *args, **kwargs):

        with self.assertRaises(SystemExit) as cm:
            file.insert_line_in_file_after_regex('/tmp/test',
                                                 'Look mum, no hands',
                                                 '.*on.*bicycle')
        self.assertEqual(cm.exception.code, 1)
Exemple #3
0
    def test_insert_line_in_file_after_regex_raises_Exception_on_failure(
            self,
            *args,
            **kwargs):

        with self.assertRaises(SystemExit) as cm:
            file.insert_line_in_file_after_regex('/tmp/test',
                                                 'Look mum, no hands',
                                                 '.*on.*bicycle')
        self.assertEqual(cm.exception.code, 1)
Exemple #4
0
    def test_insert_line_in_file_after_regex_inserts_line(
            self, *args, **kwargs):

        contents = '\n'.join(['Here I am,', 'on my bicycle', 'cool, init?'])

        expected = '\r\n'.join([
            'Here I am,', 'on my bicycle', 'Look mum, no hands', 'cool, init?'
        ])

        run('echo "%s" > /tmp/test' % contents)

        file.insert_line_in_file_after_regex('/tmp/test', 'Look mum, no hands',
                                             '.*on.*bicycle')

        self.assertEqual(sudo('cat /tmp/test'), expected)
Exemple #5
0
    def test_insert_line_in_file_after_regex_returns_True_when_changed(
            self, *args, **kwargs):

        contents = '\n'.join(['Here I am,', 'on my bicycle', 'cool, init?'])

        run('echo "%s" > /tmp/test' % contents)

        # it should return True when changed
        self.assertTrue(
            file.insert_line_in_file_after_regex('/tmp/test',
                                                 'Look mum, no hands',
                                                 '.*on.*bicycle'))
Exemple #6
0
    def test_insert_line_in_file_after_regex_returns_True_when_changed(
            self,
            *args,
            **kwargs):

        contents = '\n'.join(
            [
                'Here I am,',
                'on my bicycle',
                'cool, init?'
            ]
        )

        run('echo "%s" > /tmp/test' % contents)

        # it should return True when changed
        self.assertTrue(
            file.insert_line_in_file_after_regex('/tmp/test',
                                                 'Look mum, no hands',
                                                 '.*on.*bicycle')
        )