def test_write_stream(): value = "Hello, world!\n\nGoodby, cruel world." ms3 = boto.connect_s3() bkt = ms3.create_bucket('furi') s3furi1 = furi.open('s3://furi/foo/bar/bizz/buzz', mode='w') s3furi1.write(value) s3furi2 = furi.open('s3://furi/foo/bar/bizz/fizz', mode='w') s3furi2.write(s3furi1.stream()) assert_equal(s3furi1.read(), s3furi2.read())
def test_write(): value = "Hello, world!\n\nGoodby, cruel world." with tempfile.NamedTemporaryFile() as tmp: furifile = furi.open(tmp.name, mode='w+') furifile.write(value) furifile.stream().seek(0) assert_equal(furifile.read(), value)
def test_write(): value = "Hello, world!\n\nGoodbye, cruel world." with tempfile.NamedTemporaryFile() as tmp: furifile = furi.open(tmp.name, mode='w+') furifile.write(value) furifile.stream().seek(0) assert_equal(furifile.read(), value)
def test_stream_resets(): with open(__file__, 'r') as this: furifile = furi.open(__file__) stream = furifile.stream() stream.read() returned = furifile.read() expected = this.read() assert_equal(returned, expected)
def test_exists(): value = "Hello, world!\n\nGoodby, cruel world." ms3 = boto.connect_s3() bkt = ms3.create_bucket('furi') key = boto.s3.key.Key(bkt, 'foo/bar/bizz/buzz') key.set_contents_from_string(value) s3furi = furi.open('s3://furi/foo/bar/bizz/buzz') assert s3furi.exists()
def test_s3_read_stream(): ms3 = boto.connect_s3() bkt = ms3.create_bucket('furi') key = boto.s3.key.Key(bkt) key.name = 'foo/bar/bizz/buzz' value = "Hello, world!\n\nGoodbye, cruel world.".encode("utf-8") key.set_contents_from_string(value) with furi.open('s3://furi/foo/bar/bizz/buzz', mode='w') as s3furi: assert_equal(s3furi.read(), value)
def test_s3_stream(): value = "Hello, world!\n\nGoodbye, cruel world." ms3 = boto.connect_s3() bkt = ms3.create_bucket('furi') key = boto.s3.key.Key(bkt, 'foo/bar/bizz/buzz') key.set_contents_from_string(value) with furi.open('s3://furi/foo/bar/bizz/buzz') as tmp: tmp.stream() tmp.stream()
def test_iter(): lines = [ "This is line 1\n", "This is line 2\n"] with tempfile.NamedTemporaryFile() as tmp: for line in lines: tmp.write(line.encode("utf8")) tmp.flush() furifile = furi.open(tmp.name) returned = list(iter(furifile)) assert_equal(returned, lines)
def test_dispatch_local_no_scheme(): returned = type(furi.open('/abs/path/test')) expected = furi.File assert_equal(returned, expected)
def test_bad_scheme(): furi.open('foo://bar/path/test')
def test_dispatch_sftp(): returned = type(furi.open('sftp://*****:*****@host/path/test')) expected = furi.SftpFile assert_equal(returned, expected)
def test_dispatch_s3(): returned = type(furi.open('s3://bucket/path/to/test')) expected = furi.S3File assert_equal(returned, expected)
def test_matches(): pattern = re.compile('[A-Z][a-z]+\.[Yy][Aa]?[Mm][Ll]') furifile = furi.open('/abs/path/to/Hello.yml') assert furifile.matches(pattern)
def test_bad_mode(): furi.open("foo.txt", mode="j")
def test_read(): with open(__file__, 'r') as this: furifile = furi.open(__file__) returned = furifile.read() expected = this.read() assert_equal(returned, expected)
def test_matches(): pattern = re.compile("[A-Z][a-z]+\.[Yy][Aa]?[Mm][Ll]") furifile = furi.open("/abs/path/to/Hello.yml") assert furifile.matches(pattern)
def test_repr(): furifile = furi.open("/path/to/file") returned = repr(furifile) expected = "<File: /path/to/file>" assert_equal(returned, expected)
def test_not_matches(): pattern = re.compile('[A-Z][a-z]+\.[Yy][Aa]?[Mm][Ll]') furifile = furi.open('/abs/path/to/Hello.txt') assert not furifile.matches(pattern)
def test_cant_stream(): furi.open("/path/to/file").stream()
def test_file_exists(): furifile = furi.open(__file__) assert furifile.exists()
def test_not_file_exists(): furifile = furi.open('/foo/bar/fizz/buzz') assert not furifile.exists()
def test_not_exists(): ms3 = boto.connect_s3() bkt = ms3.create_bucket('furi') s3furi = furi.open('s3://furi/foo/bar/bizz/buzz') assert not s3furi.exists()
def test_dispatch_local_with_scheme(): returned = type(furi.open('file:///abs/path/test')) expected = furi.furifile.File assert_equal(returned, expected)
def test_connect(): s3furi = furi.open('s3://bucket/path/file') returned = s3furi.connect() expected = boto.s3.connection.S3Connection assert_is_instance(returned, expected)
def test_exists(): furifile = furi.open(__file__) assert furifile.exists()
def test_not_exists(): furifile = furi.open('/foo/bar/fizz/buzz') assert not furifile.exists()
def test_not_exists(): furifile = furi.open("/foo/bar/fizz/buzz") assert not furifile.exists()