Пример #1
0
class TestNoneEmptyDXFDict(unittest.TestCase):
    def setUp(self):
        self.dxfdict = DXFDictionary(ExtendedTags.from_text(ROOTDICT))

    def test_getitem(self):
        self.assertEqual(self.dxfdict['ACAD_PLOTSTYLENAME'], 'E')

    def test_len(self):
        self.assertEqual(14, len(self.dxfdict))

    def test_getitem_with_keyerror(self):
        with self.assertRaises(ezdxf.DXFKeyError):
            self.dxfdict['MOZMAN']

    def test_owner(self):
        self.assertEqual(self.dxfdict.dxf.owner, '0')

    def test_handle(self):
        self.assertEqual(self.dxfdict.dxf.handle, 'C')

    def test_get(self):
        self.assertEqual(self.dxfdict.get('ACAD_MOZMAN', 'XXX'), 'XXX')

    def test_get_entity(self):
        # returns just the handle, because no associated drawing exists
        self.assertEqual('E', self.dxfdict.get_entity('ACAD_PLOTSTYLENAME'))

    def test_get_with_keyerror(self):
        with self.assertRaises(ezdxf.DXFKeyError):
            self.dxfdict.get('ACAD_MOZMAN')

    def test_contains(self):
        self.assertTrue('ACAD_PLOTSTYLENAME' in self.dxfdict)

    def test_not_contains(self):
        self.assertFalse('MOZMAN' in self.dxfdict)

    def test_delete_existing_key(self):
        del self.dxfdict['ACAD_PLOTSTYLENAME']
        self.assertFalse('ACAD_PLOTSTYLENAME' in self.dxfdict)
        self.assertEqual(13, len(self.dxfdict))

    def test_delete_not_existing_key(self):
        with self.assertRaises(ezdxf.DXFKeyError):
            del self.dxfdict['MOZMAN']

    def test_remove_existing_key(self):
        self.dxfdict.remove('ACAD_PLOTSTYLENAME')
        self.assertFalse('ACAD_PLOTSTYLENAME' in self.dxfdict)
        self.assertEqual(13, len(self.dxfdict))

    def test_remove_not_existing_key(self):
        with self.assertRaises(ezdxf.DXFKeyError):
            self.dxfdict.remove('MOZMAN')

    def test_discard_existing_key(self):
        self.dxfdict.discard('ACAD_PLOTSTYLENAME')
        self.assertFalse('ACAD_PLOTSTYLENAME' in self.dxfdict)
        self.assertEqual(13, len(self.dxfdict))

    def test_discard_not_existing_key(self):
        self.dxfdict.discard('MOZMAN')
        self.assertEqual(14, len(self.dxfdict))

    def test_clear(self):
        self.assertEqual(14, len(self.dxfdict))
        self.dxfdict.clear()
        self.assertEqual(0, len(self.dxfdict))