Ejemplo n.º 1
0
 def setUp(self):
     self.raw_dictionary = {
         "TEST_BLOCK_1": {
             "_test_category_1": {
                 "test_value_1": 1,
                 "test_value_2": 2,
                 "test_value_3": 3,
             },
             "_test_category_2": {  # Loop/table
                 "test_value_1": [1, 2, 3, 4],
                 "test_value_2": ["Sleepy", "Dopey", "Bashful", "Grumpy"],
                 "test_value_3": [
                     "A ->\nLINE = A",
                     "B ->\nLINE = B",
                     "C ->\nLINE = C",
                     "D ->\nLINE = D",
                 ],
             },
         },
         "TEST_BLOCK_2": {"_test_category_1": {"test_value_1": [1, 2, 3, 4]}},
     }
     self.cf = CifFile()
Ejemplo n.º 2
0
 def test_write_ciffile_after_ciffile_dictionary_import(self):
     # Test write CifFile initialized by dictionary
     unit_test_file = "io_testcase_1.cif"
     cfw = CifFileWriter()
     cif_file = CifFile(os.path.join(self.FILE_ROOT, unit_test_file))
     cif_file.import_mmcif_data_map(self.raw_dictionary)
     cfw.write(cif_file)
     cfr = CifFileReader(input="data", preserve_order=True)
     test_file = cfr.read(os.path.join(self.FILE_ROOT, unit_test_file),
                          output="cif_wrapper")
     data_block_ids = list(test_file.keys())
     data_block_ids.sort()
     self.assertEqual(
         data_block_ids,
         ["TEST_BLOCK_1", "TEST_BLOCK_2"],
         "Datablock(s) were not written correctly",
     )
     self.assertEqual(
         test_file["TEST_BLOCK_1"]._test_category_2.test_value_1,
         ["1", "2", "3", "4"],
         "mmCIF data  was not written correctly",
     )
Ejemplo n.º 3
0
 def test_dictionaryImport(self):
     cf = CifFile()
     cf.import_mmcif_data_map(self.raw_dictionary)
     self.assertIsNotNone(cf.getDataBlock("TEST_BLOCK_2"),
                          "CifFile failed to import dictionary")
     self.assertIsInstance(
         cf.getDataBlock("TEST_BLOCK_2"),
         DataBlock,
         "CifFile.__init__ failed to import dictionary",
     )
     self.assertEqual(
         cf.getDataBlock("TEST_BLOCK_2").getCategory(
             "_test_category_1").getItem("test_value_1").value,
         [1, 2, 3, 4],
         "CifFile failed to import dictionary",
     )
Ejemplo n.º 4
0
 def setUp(self):
     self.cf = CifFile("test.cif", preserve_token_order=True)
     self.db = DataBlock("TEST", parent=self.cf)
     self.ct = Category("_foo", parent=self.db)
     self.im = Item("bar", parent=self.ct)
     str(self.im)
Ejemplo n.º 5
0
 def setUp(self):
     self.cf = CifFile("test.cif", preserve_token_order=True)
     self.db = DataBlock("TEST", parent=self.cf)
     self.sf = SaveFrame("_saveframe.test", parent=self.db)
     str(self.sf)
Ejemplo n.º 6
0
class CifFileTestCase(unittest.TestCase):
    def setUp(self):
        self.raw_dictionary = {
            "TEST_BLOCK_1": {
                "_test_category_1": {
                    "test_value_1": 1,
                    "test_value_2": 2,
                    "test_value_3": 3,
                },
                "_test_category_2": {  # Loop/table
                    "test_value_1": [1, 2, 3, 4],
                    "test_value_2": ["Sleepy", "Dopey", "Bashful", "Grumpy"],
                    "test_value_3": [
                        "A ->\nLINE = A",
                        "B ->\nLINE = B",
                        "C ->\nLINE = C",
                        "D ->\nLINE = D",
                    ],
                },
            },
            "TEST_BLOCK_2": {"_test_category_1": {"test_value_1": [1, 2, 3, 4]}},
        }
        self.cf = CifFile()

    #    def tearDown(self):
    #        self.foo.dispose()
    #        self.foo = None

    def test_setDataBlock(self):
        db = self.cf.setDataBlock("TEST")
        self.assertIsInstance(
            db, DataBlock, "CifFile.setDataBlock created an invalid object")
        db2 = self.cf.setDataBlock(DataBlock("TEST", parent=self.cf))
        self.assertIsInstance(
            db2, DataBlock, "CifFile.setDataBlock created an invalid object")

    def test_registerChild(self):
        db = DataBlock("TEST", self.cf)
        self.assertIsInstance(
            self.cf.getDataBlock("TEST"),
            DataBlock,
            "CifFile.getDataBlock returned an invalid object",
        )

    def test_getDataBlock(self):
        self.cf.setDataBlock("TEST")
        self.assertIsInstance(
            self.cf.getDataBlock("TEST"),
            DataBlock,
            "CifFile.getDataBlock returned an invalid object",
        )

    def test_getDataBlockIds(self):
        self.cf.setDataBlock("TEST")
        msg = "CifFile.getDataBlockIds returned incorrect list of DataBlock IDs"
        self.assertListEqual(self.cf.getDataBlockIds(), [
            "TEST",
        ], msg)

    def test_getDataBlocks(self):
        db = self.cf.setDataBlock("TEST")
        msg = "CifFile.getDataBlocks returned incorrect list of DataBlocks"
        self.assertListEqual(self.cf.getDataBlocks(), [
            db,
        ], msg)

    def test_removeChildByString(self):
        db = self.cf.setDataBlock("TEST")
        msg = "CifFile.removeChild"
        self.assertTrue(self.cf.removeChild("TEST"),
                        msg + " did not return expected True")
        self.assertListEqual(self.cf.getDataBlocks(), [],
                             msg + " datablocks should be an empty list")
        self.assertIsInstance(
            self.cf.recycleBin.get("TEST"),
            DataBlock,
            msg + " recyclebin should contain a DataBlock instance",
        )
        self.assertEqual(
            self.cf.recycleBin.get("TEST"),
            db,
            msg + " recyclebin should contain the datablock instance",
        )

    def test_removeChildByObj(self):
        db = self.cf.setDataBlock("TEST")
        msg = "CifFile.removeChild"
        self.assertTrue(self.cf.removeChild(db),
                        msg + " did not return expected True")
        self.assertListEqual(self.cf.getDataBlocks(), [],
                             msg + " datablocks should be an empty list")
        self.assertIsInstance(
            self.cf.recycleBin.get("TEST"),
            DataBlock,
            msg + " recyclebin should contain a DataBlock instance",
        )
        self.assertEqual(
            self.cf.recycleBin.get("TEST"),
            db,
            msg + " recyclebin should contain the datablock instance",
        )

    def test_removeChildBadRef(self):
        self.cf.setDataBlock("TEST")
        msg = "CifFile.removeChild"
        self.assertFalse(self.cf.removeChild("FAIL"),
                         msg + " did not return expected False")

    def test_dictionaryImport(self):
        cf = CifFile()
        cf.import_mmcif_data_map(self.raw_dictionary)
        self.assertIsNotNone(cf.getDataBlock("TEST_BLOCK_2"),
                             "CifFile failed to import dictionary")
        self.assertIsInstance(
            cf.getDataBlock("TEST_BLOCK_2"),
            DataBlock,
            "CifFile.__init__ failed to import dictionary",
        )
        self.assertEqual(
            cf.getDataBlock("TEST_BLOCK_2").getCategory(
                "_test_category_1").getItem("test_value_1").value,
            [1, 2, 3, 4],
            "CifFile failed to import dictionary",
        )

    def test_initializeWithDictionary(self):
        cf = CifFile(mmcif_data_map=self.raw_dictionary)

        self.assertIsInstance(cf, CifFile,
                              "CifFile.__init__ failed to import dictionary")
        self.assertIsNotNone(
            cf.getDataBlock("TEST_BLOCK_2"),
            "CifFile.__init__ failed to import dictionary",
        )
        self.assertEqual(
            cf.getDataBlock("TEST_BLOCK_2").getCategory(
                "_test_category_1").getItem("test_value_1").value,
            [1, 2, 3, 4],
            "CifFile.__init__ failed to import dictionary",
        )
        cf = CifFile(mmcif_data_map={})
Ejemplo n.º 7
0
 def setUp(self):
     self.cf = CifFile("test.cif", preserve_token_order=True)
     self.db = DataBlock("TEST", parent=self.cf)
     str(self.db)