# Path: contrail_api_cli/utils.py
# class Path(PurePosixPath):
#     _flavour = APIFlavour()
# 
#     @classmethod
#     def _from_parsed_parts(cls, drv, root, parts, init=True):
#         if parts:
#             parts = [root] + os.path.relpath(os.path.join(*parts),
#                                              start=root).split(os.path.sep)
#             parts = [p for p in parts if p not in (".", "")]
#         return super(cls, Path)._from_parsed_parts(drv, root, parts, init)
# 
#     def __init__(self, *args):
#         self.meta = {}
# 
#     @property
#     def base(self):
#         try:
#             return self.parts[1]
#         except IndexError:
#             pass
#         return ''
# 
#     @property
#     def is_root(self):
#         return len(self.parts) == 1 and self.root == "/"
# 
#     @property
#     def is_fq_name(self):
#         return not self.is_uuid
# 
#     @property
#     def is_uuid(self):
#         try:
#             UUID(self.name, version=4)
#         except (ValueError, IndexError):
#             return False
#         return True
# 
#     @property
#     def is_resource(self):
#         """The path is a resource if it is not a Collection
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         return not self.is_collection
# 
#     @property
#     def is_collection(self):
#         """The path is a Collection if there is only one part in the path. Be
#         careful, the root is a Collection.
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         if not self.is_absolute():
#             raise AbsPathRequired()
#         return self.base == self.name
# 
#     def relative_to(self, path):
#         try:
#             return PurePosixPath.relative_to(self, path)
#         except ValueError:
#             return self
# 
# Path: contrail_api_cli/exceptions.py
# class AbsPathRequired(Exception):
#     pass


import unittest
from uuid import uuid4
from contrail_api_cli.utils import Path
from contrail_api_cli.exceptions import AbsPathRequired
        p = p / "foo" / "bar"
        self.assertEqual(str(p), "/foo/bar")
        p = p / ".." / "foo"
        self.assertEqual(str(p), "/foo/foo")

    def test_resource(self):
        p = Path("/foo/%s" % str(uuid4()))
        self.assertTrue(p.is_resource)
        p = Path("/foo/bar")
        self.assertTrue(p.is_resource)
        p = Path("/")
        self.assertFalse(p.is_resource)
        p = Path("/75963ada-2c70-4eeb-8daf-f24ce920ff7b")
        self.assertFalse(p.is_resource)
        p = Path("foo/bar")
        with self.assertRaises(AbsPathRequired):
            p.is_resource

    def test_collection(self):
        p = Path("/foo")
        self.assertTrue(p.is_collection)
        p = Path("/foo/bar")
        self.assertFalse(p.is_collection)
        p = Path("/")
        self.assertTrue(p.is_collection)
        p = Path("foo/bar")
        with self.assertRaises(AbsPathRequired):
            p.is_collection

    def test_uuid(self):

# Path: contrail_api_cli/utils.py
# class Path(PurePosixPath):
#     _flavour = APIFlavour()
# 
#     @classmethod
#     def _from_parsed_parts(cls, drv, root, parts, init=True):
#         if parts:
#             parts = [root] + os.path.relpath(os.path.join(*parts),
#                                              start=root).split(os.path.sep)
#             parts = [p for p in parts if p not in (".", "")]
#         return super(cls, Path)._from_parsed_parts(drv, root, parts, init)
# 
#     def __init__(self, *args):
#         self.meta = {}
# 
#     @property
#     def base(self):
#         try:
#             return self.parts[1]
#         except IndexError:
#             pass
#         return ''
# 
#     @property
#     def is_root(self):
#         return len(self.parts) == 1 and self.root == "/"
# 
#     @property
#     def is_fq_name(self):
#         return not self.is_uuid
# 
#     @property
#     def is_uuid(self):
#         try:
#             UUID(self.name, version=4)
#         except (ValueError, IndexError):
#             return False
#         return True
# 
#     @property
#     def is_resource(self):
#         """The path is a resource if it is not a Collection
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         return not self.is_collection
# 
#     @property
#     def is_collection(self):
#         """The path is a Collection if there is only one part in the path. Be
#         careful, the root is a Collection.
# 
#         :raises AbsPathRequired: path doesn't start with '/'
#         """
#         if not self.is_absolute():
#             raise AbsPathRequired()
#         return self.base == self.name
# 
#     def relative_to(self, path):
#         try:
#             return PurePosixPath.relative_to(self, path)
#         except ValueError:
#             return self
# 
# Path: contrail_api_cli/exceptions.py
# class AbsPathRequired(Exception):
#     pass


# Path: contrail_api_cli/tests/test_path.py
import unittest
from uuid import uuid4
from contrail_api_cli.utils import Path
from contrail_api_cli.exceptions import AbsPathRequired

        p = p / "foo" / "bar"
        self.assertEqual(str(p), "/foo/bar")
        p = p / ".." / "foo"
        self.assertEqual(str(p), "/foo/foo")

    def test_resource(self):
        p = Path("/foo/%s" % str(uuid4()))
        self.assertTrue(p.is_resource)
        p = Path("/foo/bar")
        self.assertTrue(p.is_resource)
        p = Path("/")
        self.assertFalse(p.is_resource)
        p = Path("/75963ada-2c70-4eeb-8daf-f24ce920ff7b")
        self.assertFalse(p.is_resource)
        p = Path("foo/bar")
        with self.assertRaises(AbsPathRequired):
            p.is_resource

    def test_collection(self):
        p = Path("/foo")
        self.assertTrue(p.is_collection)
        p = Path("/foo/bar")
        self.assertFalse(p.is_collection)
        p = Path("/")
        self.assertTrue(p.is_collection)
        p = Path("foo/bar")
        with self.assertRaises(AbsPathRequired):
            p.is_collection

    def test_uuid(self):

        p = Path("/foo/%s" % str(uuid4()))