示例#1
0
def test_read(tmpdir):
    with tmpdir.as_cwd():
        t1 = tmpdir.join('abc0')
        t1.write(b'abc')
        t2 = tmpdir.join('abc1')
        t2.write(b'123')
        f = open_file('abc', 'r')
        assert f.read(10) == b'abc123'
        f = open_file('abc', 'r')
        assert f.read() == b'abc123'
        f = open_file('abc', 'r', buffer_size=2)
        assert f.read() == b'ab'
        assert f.read() == b'c1'
        assert f.read() == b'23'
示例#2
0
def test_readline(tmpdir):
    with tmpdir.as_cwd():
        t1 = tmpdir.join('abc0')
        t1.write(b'abc')
        t2 = tmpdir.join('abc1')
        t2.write(b'123\n')
        f = open_file('abc', 'r')
        assert f.readline() == b'abc123\n'
示例#3
0
def test_close(tmpdir):
    with tmpdir.as_cwd():
        f = open_file('abc', 'w', roll_size=10)
        f.write(b'abc')
        f.close()
        assert f.closed == True
        with pytest.raises(ValueError):
            f.write(b'123')
示例#4
0
def test_flush(tmpdir):
    with tmpdir.as_cwd():
        f = open_file('abc', 'w')
        f.write(b'data1')
        f.flush()
        f.close()
        with pytest.raises(ValueError):
            f.flush()
示例#5
0
def test_read_single_file(tmpdir):
    with tmpdir.as_cwd():
        word = b"abc"
        f = tmpdir.join('abc')
        f.write(word)
        f = open_file('abc', 'r')
        c = f.read()
        assert c == word
示例#6
0
def test_write_rotate(tmpdir):
    with tmpdir.as_cwd():
        f = open_file('abc', 'w', roll_size=10)
        f.write(b'1' * 100)
        f.close()
        for i in range(0, 10):
            fn = 'abc%d' % i
            assert os.path.exists(fn)
            assert os.path.getsize(fn) == 10
示例#7
0
def test_write_max_idx(tmpdir):
    with tmpdir.as_cwd():
        f1 = tmpdir.join('abc0')
        f1.write(b'abc')
        f1 = tmpdir.join('abc3')
        f1.write(b'123')
        f = open_file('abc', 'w', roll_size=3)
        f.write(b'xyz')
        f.close()
        f = open('abc4')
        c = f.read()
        assert len(c) == 3
示例#8
0
def test_write_append(tmpdir):
    with tmpdir.as_cwd():
        f1 = tmpdir.join('abc0')
        f1.write(b'abc')
        f = open_file('abc', 'w', roll_size=4)
        f.write(b'1234')
        f.close()
        f = open('abc0', 'rb')
        c = f.read()
        assert c == b'abc1'
        f = open('abc1', 'rb')
        c = f.read()
        assert c == b'234'
示例#9
0
 def process_arguments(self, args):
     super(Get, self).process_arguments(args)
     output = None
     if args.output is None:
         output = binary_stdout
     else:
         if not hasattr(args, 'output_type'):
             output = open(args.output, 'ab')
         elif args.output_type == 'single':
             output = open(args.output, 'ab')
         elif args.output_type == 'rotate':
             from os_rotatefile import open_file
             output = open_file(args.output, 'w')
     self.config.output = output
示例#10
0
def test_mode(tmpdir):
    with tmpdir.as_cwd():
        with pytest.raises(ValueError):
            open_file('abc', 'c')