示例#1
0
    def test_to_data_lid(self) -> None:
        data_coll_lid = LID("urn:nasa:pds:bundle:data_collection_raw")
        browse_coll_lid = LID("urn:nasa:pds:bundle:browse_collection_raw")
        self.assertEqual(data_coll_lid, browse_coll_lid.to_data_lid())

        browse_prod_lid = LID("urn:nasa:pds:bundle:browse_collection_raw:data_product")
        data_prod_lid = LID("urn:nasa:pds:bundle:data_collection_raw:data_product")
        self.assertEqual(data_prod_lid, browse_prod_lid.to_data_lid())
示例#2
0
    def test_create_lid_from_parts(self) -> None:
        parts: List[str] = []
        with self.assertRaises(ValueError):
            LID.create_from_parts(parts)

        parts = ["b"]
        self.assertEqual(LID("urn:nasa:pds:b"), LID.create_from_parts(parts))

        parts = ["b", "c"]
        self.assertEqual(LID("urn:nasa:pds:b:c"), LID.create_from_parts(parts))

        parts = ["b", "c", "p"]
        self.assertEqual(LID("urn:nasa:pds:b:c:p"), LID.create_from_parts(parts))

        parts = ["b", "c", "p", "x"]
        with self.assertRaises(ValueError):
            LID.create_from_parts(parts)
示例#3
0
文件: lidvid.py 项目: SETI/pdart
 def __init__(self, lidvid_str: str) -> None:
     """
     Create a LIDVID object from a string, raising an exception if
     the LIDVID string is malformed.
     """
     segs = lidvid_str.split("::")
     if len(segs) != 2:
         raise ValueError(f"The number of {lidvid_str} segments: " +
                          f"{len(segs)}, exepct 2.")
     self._lidvid = lidvid_str
     self._lid = LID(segs[0])
     self._vid = VID(segs[1])
示例#4
0
def read_changes_dict(changes_path: str) -> CHANGES_DICT:
    changes_dict = dict()
    with open(changes_path, "r") as f:
        for line in f:
            parts = line.strip().split()
            if parts:
                if len(parts) != 3:
                    raise ValueError(
                        f"Length of parts {parts} for changes_dict is not 3.")
                lid, vid, changed = parts
                if changed not in ["False", "True"]:
                    raise ValueError(
                        f"{changed} from parts has unexpected value.")
                changes_dict[LID(lid)] = (VID(vid), changed == "True")
    return ChangesDict(changes_dict)
示例#5
0
 def test_eq(self) -> None:
     self.assertTrue(
         LID("urn:nasa:pds:bundle:collection:product")
         == LID("urn:nasa:pds:bundle:collection:product")
     )
     self.assertFalse(
         LID("urn:nasa:pds:bundle:collection:product")
         != LID("urn:nasa:pds:bundle:collection:product")
     )
     self.assertFalse(
         LID("urn:nasa:pds:bundle:collection:product")
         == LID("urn:nasa:pds:bundle:collection:produit")
     )
     self.assertTrue(
         LID("urn:nasa:pds:bundle:collection:product")
         != LID("urn:nasa:pds:bundle:collection:produit")
     )
示例#6
0
文件: test_lidvid.py 项目: SETI/pdart
 def test_lid(self) -> None:
     self.assertEqual(LID("urn:nasa:pds:b:c:p"),
                      LIDVID("urn:nasa:pds:b:c:p::666.666").lid())
示例#7
0
文件: test_lidvid.py 项目: SETI/pdart
 def test_create_from_lid_and_vid(self) -> None:
     lid = LID("urn:nasa:pds:ssc01.hirespc.cruise:browse")
     vid = VID("2.5")
     lidvid = LIDVID.create_from_lid_and_vid(lid, vid)
     self.assertEqual(
         LIDVID("urn:nasa:pds:ssc01.hirespc.cruise:browse::2.5"), lidvid)
示例#8
0
文件: demo.py 项目: SETI/pdart
        " and add 'bar/', 'foo/baz.pdf', and 'foo/quux.txt'."
    )
    c.remove("foo/bar.txt")
    c.makedir("bar/")
    c.touch("foo/baz.pdf")
    c.touch("foo/quux.txt")
    print("Now the copy-on-write filesystem looks like this:")
    c.tree()
    print("But the original read-only filesystem still looks like this:")
    ro.tree()


# We define a global Multiversioned object so it can be used by more
# than demo function.
m: Optional[Multiversioned] = None
lid = LID("urn:nasa:pds:hst_00001")


def demo_multi() -> None:
    """
    Demonstration of the use of a Multiversioned object.
    """
    global m

    # Create a version 1 of a bundle in its own directory.
    os.mkdir("demo/v1")
    v1 = OSFS("demo/v1")
    v1.makedirs("hst_00001$/data_acs_raw$/j12345s$")
    v1.writetext(
        "hst_00001$/data_acs_raw$/j12345s$/j12345s_raw.fits", "This is a FITS file."
    )
示例#9
0
 def test_eq_property(self, lhs: str, rhs: str) -> None:
     # two LIDs are equal iff their strings are equal
     self.assertEqual(lhs == rhs, LID(lhs) == LID(rhs))
示例#10
0
    def test_init(self) -> None:
        # test segments
        with self.assertRaises(Exception):
            LID("urn:nasa")
        with self.assertRaises(Exception):
            LID("urn:nasa:pds")
        LID("urn:nasa:pds:bundle")
        LID("urn:nasa:pds:bundle:container")
        LID("urn:nasa:pds:bundle:container:product")
        with self.assertRaises(Exception):
            LID("urn:nasa:pds:bundle:container:product:ingredient")

        # test prefix
        with self.assertRaises(Exception):
            LID("urn:nasa:pdddddds:bundle")

        # test length
        LID(f"urn:nasa:pds:{'a'*200}")
        with self.assertRaises(Exception):
            LID(f"urn:nasa:pds:{'a'*250}")

        # test characters
        with self.assertRaises(Exception):
            LID("urn:nasa:pds:foo&bar")
        with self.assertRaises(Exception):
            LID("urn:nasa:pds:fooBAR")
        with self.assertRaises(Exception):
            LID("urn:nasa:pds::foobar")

        # test fields
        lid = LID("urn:nasa:pds:bundle")
        self.assertEqual("bundle", lid.bundle_id)
        self.assertIsNone(lid.collection_id)
        self.assertIsNone(lid.product_id)
        self.assertEqual("urn:nasa:pds:bundle", lid.lid)

        lid = LID("urn:nasa:pds:bundle:collection")
        self.assertEqual("bundle", lid.bundle_id)
        self.assertEqual("collection", lid.collection_id)
        self.assertIsNone(lid.product_id)
        self.assertEqual("urn:nasa:pds:bundle:collection", lid.lid)

        lid = LID("urn:nasa:pds:bundle:collection:product")
        self.assertEqual("bundle", lid.bundle_id)
        self.assertEqual("collection", lid.collection_id)
        self.assertEqual("product", lid.product_id)
        self.assertEqual("urn:nasa:pds:bundle:collection:product", lid.lid)
示例#11
0
 def test_to_shm_lid(self) -> None:
     data_coll_lid = LID("urn:nasa:pds:bundle:data_collection_raw:product")
     shm_coll_lid = LID("urn:nasa:pds:bundle:data_collection_shm:product")
     self.assertEqual(shm_coll_lid, data_coll_lid.to_shm_lid())
示例#12
0
 def test_repr(self) -> None:
     self.assertEqual(
         "LID('urn:nasa:pds:bundle:collection:product')",
         repr(LID("urn:nasa:pds:bundle:collection:product")),
     )
示例#13
0
 def test_str_roundtrip_property(self, lid_str: str) -> None:
     """
     Creating a LID from a string and turning it back into a string
     should result in the same string.
     """
     self.assertEqual(lid_str, str(LID(lid_str)))
示例#14
0
 def test_str(self) -> None:
     self.assertEqual(
         "urn:nasa:pds:bundle:collection:product",
         str(LID("urn:nasa:pds:bundle:collection:product")),
     )