Exemple #1
0
    def test_cutLine_bytesOutOfRangeInColumnRangeFromBegin(self):

        with patch('sys.stdout', new=StringIO()) as mockStdout:
            inputFile = StringIO('abcdef\nghijklm\nnopqrs\ntuvwxyz')
            options = {'bytes': [[0, 7]]}

            cut.cutLines(inputFile, options)

        self.assertTrue(
            'abcdef\nghijklm\nnopqrs\ntuvwxyz\n' == mockStdout.getvalue())
Exemple #2
0
    def test_cutLine_fieldsOutOfRangeInColumnRangeFromBegin(self):

        with patch('sys.stdout', new=StringIO()) as mockStdout:
            inputFile = StringIO(
                'ab;cd;ef;gh;ij\nkl;mn;op;qr;st\nuv;wx;yz;12;34;56')
            options = {'fields': [[0, 7]], 'delimiter': ';'}

            cut.cutLines(inputFile, options)

        self.assertTrue('ab;cd;ef;gh;ij\nkl;mn;op;qr;st\nuv;wx;yz;12;34;56\n'
                        == mockStdout.getvalue())
Exemple #3
0
    def test_cutLine_fieldsMultipleLinesAndSingleColumnAndRange(self):

        with patch('sys.stdout', new=StringIO()) as mockStdout:
            inputFile = StringIO(
                'ab;cd;ef;gh;ij\nkl;mn;op;qr;st\nuv;wx;yz;12;34;56')
            options = {'fields': [[1, 3], [4, 5]], 'delimiter': ';'}

            cut.cutLines(inputFile, options)

        self.assertTrue(
            'cd;ef;ij\nmn;op;st\nwx;yz;34\n' == mockStdout.getvalue())
Exemple #4
0
    def test_cutLine_fieldsMultipleLinesAndSingleColumnAndRangeFromBegin(self):

        with patch('sys.stdout', new=StringIO()) as mockStdout:
            inputFile = StringIO(
                'ab;cd;ef;gh;ij\nkl;mn;op;qr;st\nuv;wx;yz;12;34;56')
            options = {'fields': [[3, 4], [0, 2]], 'delimiter': ';'}

            cut.cutLines(inputFile, options)

        self.assertTrue(
            'gh;ab;cd\nqr;kl;mn\n12;uv;wx\n' == mockStdout.getvalue())
Exemple #5
0
    def test_cutLine_fieldsMultipleLinesChosenOutputDelimiter(self):

        with patch('sys.stdout', new=StringIO()) as mockStdout:
            inputFile = StringIO('ab;cd;ef;gh;ij;kl;m\nno;pq;rs;tu;vw;xy;z')
            options = {
                'fields': [[1, 3], [5, 6]],
                'delimiter': ';',
                'outputDelimiter': '_'
            }

            cut.cutLines(inputFile, options)

        self.assertTrue('cd_ef_kl\npq_rs_xy\n' == mockStdout.getvalue())
Exemple #6
0
    def test_cutLine_fieldsComplementMultipleLines(self):

        with patch('sys.stdout', new=StringIO()) as mockStdout:
            inputFile = StringIO('ab;cd;ef;gh;ij;kl;m\nno;pq;rs;tu;vw;xy;z')
            options = {
                'fields': [[1, 3], [5, 6]],
                'delimiter': ';',
                'complement': True
            }

            cut.cutLines(inputFile, options)

        self.assertTrue('ab;gh;ij;m\nno;tu;vw;z\n' == mockStdout.getvalue())
Exemple #7
0
    def test_cutLine_fieldsMultipleLinesOnlyDelimited(self):

        with patch('sys.stdout', new=StringIO()) as mockStdout:
            inputFile = StringIO('ab;cd;ef;gh\nijklmnop\nrs;tu;vw;xy;z')
            options = {
                'fields': [[0, 1], [3, 4]],
                'delimiter': ';',
                'outputDelimiter': ' ',
                'onlyDelimited': True
            }

            cut.cutLines(inputFile, options)

        #   sys.stderr.write( '[debug] result: \'' + mockStdout.getvalue() + '\'\n' )
        self.assertTrue('ab gh\nrs xy\n' == mockStdout.getvalue())