def test_equal(self):
     """ read from disk,  test equality """
     sdc1 = cd.simpleCollection()
     sdc1.create_from_disk(self.datadir)
     sdc2 = cd.simpleCollection()
     sdc2.create_from_disk(self.datadir)
     self.assertEqual(sdc1, sdc2)
 def test_update_collection(self):
     sdc = cd.simpleCollection()
     sdc.create_from_disk(self.datadir)
     time.sleep(1)
     os.mkdir(self.d2)
     makeDummyNC(self.f4)
     sdc2 = cd.simpleCollection()
     sdc2.create_from_disk(self.datadir)
     sdc.update()
     # print sdc it's all there
     # print sdc2 all there
     self.assertEqual(sdc, sdc2)
 def test_update_file(self):
     sdc = cd.simpleCollection()
     sdc.create_from_disk(self.datadir)
     makeDummyNC(self.f3)
     sdc.update()
     # if the update hasn't picked up the modification date then
     # we'll fail here:
     subdircon = sdc.contents["subCollections"][0]
     self.assertEqual(len(subdircon.contents["dataFiles"]), 2, "possible issue with timing in tests")
     sdc_copy = cd.simpleCollection()
     sdc_copy.create_from_disk(self.datadir)
     self.assertEqual(sdc_copy, sdc)
 def test_create_from_disk(self):
     """ test creating a collection document from disk """
     sdc = cd.simpleCollection()
     sdc.create_from_disk(self.datadir)
     # just check one property:
     path = sdc.properties["path"]
     self.assertEqual(path, self.datadir)
 def test_size_aggregation(self):
     """ test that variable sizes are aggregated properly """
     sdc = cd.simpleCollection()
     makeDummyNC(self.f3)
     n = 30 * 12 * 4 * 12 * 2
     sdc.create_from_disk(self.datadir)
     ss = sdc.contents["subCollections"][0]
     for v in ss.contents["myvariables"]:
         self.assertEqual(n, v.properties["size"])
 def test_serialiseFromCF(self):
     """ Test round trip serialisation of material from the CF
     contents """
     tmp = cd.simpleCollection()
     tmp.create_from_disk(self.datadir)
     s = tmp.serialise()
     print s
     y = cd.simpleSerialiser(cd.simpleChecker)
     tmp2 = y.deserialise(s)
     self.assertEqual(tmp, tmp2)
 def test_checkondisk2(self):
     """ Test that we can see extra files in a directory"""
     # note that we don't have guaranteed resolution in time of <1s
     # so this currently fails.
     # need a c extension to get to st_mtim not st_mtime.
     # base around http://goo.gl/W2Twb ?
     sdc = cd.simpleCollection()
     sdc.create_from_disk(self.datadir)
     time.sleep(0.1)
     x = os.listdir(self.d1)  # wait,flush
     makeDummyNC(self.f3)
     time.sleep(0.1)
     x = os.listdir(self.d1)  # wait,flush
     self.assertRaises(cd.ValidationError, sdc.check_ondisk)
    def setUp(self):

        # first don't go near disk
        self.dummysf = cd.simpleDataFile()
        self.now = datetime.datetime.now().isoformat()
        self.dummyproperties = {
            "modificationDate": self.now,
            "checksum": "dummychecksum",
            "path": "dummypath",
            "name": "dummyname",
        }
        for k in self.dummyproperties:
            self.dummysf.modify(k, self.dummyproperties[k])
        self.dummysc = cd.simpleCollection(cd.simpleSerialiser)
        for k in ["modificationDate"]:
            self.dummysc.modify(k, self.dummyproperties[k])
        self.dummysc.add("dataFiles", self.dummysf)

        # now what we need for physical CF metadata serialisation
        self.datadir = tempfile.mkdtemp()
        self.f1 = os.path.join(self.datadir, "file1.nc")
        makeDummyNC(self.f1)
 def test_checkondisk1(self):
     """ Test the check on disk when it's all kosher """
     sdc = cd.simpleCollection()
     sdc.create_from_disk(self.datadir)
     self.assertTrue(sdc.check_ondisk)