Пример #1
0
    def wrapped():
        """
        The new callable.
        """

        with mkdtemp_scoped() as directory:
            url = "sqlite:///%s" % join(directory, "testing.sqlite")

            with disposing(create_engine(url, echo = False)) as engine:
                return callable(engine)
Пример #2
0
def test_save_load_json():
    """
    Test trivial JSON save and load.
    """

    from nose.tools import assert_equal
    from os.path import join
    from cargo.io import mkdtemp_scoped
    from cargo.json import save_json, load_json

    with mkdtemp_scoped() as sandbox_path:
        json_path = join(sandbox_path, "test.json")
        json_data = {"foo": 42, "bar": "baz"}

        save_json(json_data, json_path)

        loaded_data = load_json(json_path)

        assert_equal(loaded_data, json_data)
Пример #3
0
def test_files_under():
    """
    Test directory traversal using files_under().
    """

    from cargo.io import mkdtemp_scoped

    with mkdtemp_scoped() as box_path:
        # build a fake directory tree
        from os import makedirs
        from os.path import join

        directories = [
            join(box_path, "foo/bar/baz"),
            join(box_path, "foo/aaa/bbb"),
            join(box_path, "qux/ccc"),
        ]

        for name in directories:
            makedirs(name)

        files = [
            join(box_path, "qux/ccc/blob.a"),
            join(box_path, "qux/ccc/blub.b"),
        ]

        for name in files:
            open(name, "w").close()

        # traverse it
        from nose.tools import assert_equal
        from cargo.io import files_under

        assert_equal(sorted(files_under(box_path)), sorted(files))
        assert_equal(sorted(files_under(box_path, "*.a")), files[:1])
        assert_equal(sorted(files_under(box_path, ["*.a", "*.b"])),
                     sorted(files))

        assert_equal(list(files_under(files[0])), files[:1])
        assert_equal(list(files_under(directories[0])), [])
Пример #4
0
def test_files_under():
    """
    Test directory traversal using files_under().
    """

    from cargo.io import mkdtemp_scoped

    with mkdtemp_scoped() as box_path:
        # build a fake directory tree
        from os      import makedirs
        from os.path import join

        directories = [
            join(box_path, "foo/bar/baz"),
            join(box_path, "foo/aaa/bbb"),
            join(box_path, "qux/ccc"),
            ]

        for name in directories:
            makedirs(name)

        files = [
            join(box_path, "qux/ccc/blob.a"),
            join(box_path, "qux/ccc/blub.b"),
            ]

        for name in files:
            open(name, "w").close()

        # traverse it
        from nose.tools import assert_equal
        from cargo.io   import files_under

        assert_equal(sorted(files_under(box_path)),                 sorted(files))
        assert_equal(sorted(files_under(box_path, "*.a")),          files[:1])
        assert_equal(sorted(files_under(box_path, ["*.a", "*.b"])), sorted(files))

        assert_equal(list(files_under(files[0])),       files[:1])
        assert_equal(list(files_under(directories[0])), [])
Пример #5
0
def test_save_load_json():
    """
    Test trivial JSON save and load.
    """

    from nose.tools import assert_equal
    from os.path import join
    from cargo.io import mkdtemp_scoped
    from cargo.json import (
        save_json,
        load_json,
    )

    with mkdtemp_scoped() as sandbox_path:
        json_path = join(sandbox_path, "test.json")
        json_data = {"foo": 42, "bar": "baz"}

        save_json(json_data, json_path)

        loaded_data = load_json(json_path)

        assert_equal(loaded_data, json_data)