コード例 #1
0
ファイル: test_furifile.py プロジェクト: amancevice/furi
def test_s3_walk():
    value = "Hello, world!\n\nGoodbye, cruel world."
    ms3 = boto.connect_s3()
    bkt = ms3.create_bucket('furi')

    keys = ['foo/baq/bug', 'foo/bar/bizz/buzz', 'foo/bar/bizz/fizz', 'foo/ban']
    for keyname in keys:
        key = boto.s3.key.Key(bkt)
        key.name = keyname
        key.set_contents_from_string(value)

    returned = list(furi.walk('s3://furi/foo/'))
    expected = [
        ('s3://furi/foo/',          ['baq', 'bar'],  ['ban']),
        ('s3://furi/foo/baq/',      [],              ['bug']),
        ('s3://furi/foo/bar/',      ['bizz'],        []),
        ('s3://furi/foo/bar/bizz/', [],              ['buzz', 'fizz'])]
    assert_equal(returned, expected)
コード例 #2
0
ファイル: test_furifile.py プロジェクト: amancevice/furi
def test_walk():
    with tempfile.NamedTemporaryFile() as tmp:
        path = os.path.split(tmp.name)[0]
        os.chdir(path)
        keys = [
            'foo/baq/bug', 'foo/bar/bizz/buzz', 'foo/bar/bizz/fizz', 'foo/ban']
        for keyname in keys:
            fpath, fname = os.path.split(keyname)
            if not os.path.exists(fpath):
                os.makedirs(fpath)
            with open(keyname, 'w') as tmpf:
                tmpf.write("Hello, world!\n\nGoodbye, cruel world.")

        returned = list(furi.walk('foo'))
        expected = [
            ('foo',          ['baq', 'bar'],  ['ban']),
            ('foo/baq',      [],              ['bug']),
            ('foo/bar',      ['bizz'],        []),
            ('foo/bar/bizz', [],              ['buzz', 'fizz'])]
        assert_equal(returned, expected)