# Copyright (c) 2017 The Regents of the University of Michigan.
# All Rights Reserved. Licensed according to the terms of the Revised
# BSD License. See LICENSE.txt for details.
from hamcrest import *
import unittest
from .hamcrest import evaluates_to

from blister.xmp import XMP

class GivenEmptyXMP (unittest.TestCase):

    def setUp (self):
        self.xmp = XMP()

    def test_degenerate (self):
        assert_that(self.xmp, evaluates_to(False))
        assert_that(self.xmp, has_length(0))
        assert_that(list(self.xmp), is_(equal_to([])))

    def test_not_all_attrs_exist (self):
        assert_that(calling(getattr).with_args(self.xmp,
                                               "fake_namespace"),
                    raises(AttributeError))
        assert_that(calling(getattr).with_args(self.xmp, "also_fake"),
                    raises(AttributeError))

    def test_default_xmp_namespaces_are_empty (self):
        assert_that(self.xmp.stRef, has_length(0))
        assert_that(self.xmp.dc, has_length(0))
        assert_that(self.xmp.xmp, has_length(0))
        assert_that(self.xmp.xmpRights, has_length(0))
        assert_that(self.xmp.xmpMM, has_length(0))
        assert_that(self.xmp.xmpidq, has_length(0))
        assert_that(self.xmp.exifEX, has_length(0))
        assert_that(self.xmp.exif, has_length(0))
        assert_that(self.xmp.tiff, has_length(0))

    def test_namespaces_are_also_accessible_via_getitem (self):
        assert_that(calling(lambda x: x["fake"]).with_args(self.xmp),
                    raises(KeyError))

@@ -317,16 +317,194 @@
 Case):%0A%0A
+    namespaces = (%0A        %22stRef%22,%0A        %22dc%22,%0A        %22xmp%22,%0A        %22xmpRights%22,%0A        %22xmpMM%22,%0A        %22xmpidq%22,%0A        %22exifEX%22,%0A        %22exif%22,%0A        %22tiff%22,%0A    )%0A%0A
     def 
@@ -1117,131 +1117,94 @@
     
-assert_that(self.xmp.stRef, has_length(0))%0A        assert_that(self.xmp.dc, has_length(0))%0A        assert_that(self.xmp.xmp
+for namespace in self.namespaces:%0A            assert_that(getattr(self.xmp, namespace)
 , ha
@@ -1220,382 +1220,180 @@
 0))%0A
+%0A
     
-    assert_that(self.xmp.xmpRights, has_length(0))%0A        assert_that(self.xmp.xmpMM, has_length(0))%0A        assert_that(self.xmp.xmpidq, has_length(0))%0A        assert_that(self.xmp.exifEX, has_length(0))%0A        assert_that(self.xmp.exif, has_length(0))%0A        assert_that(self.xmp.tiff, has_length(0))%0A%0A    def test_namespaces_are_also_accessible_via_getitem (self):
+def test_namespaces_are_also_accessible_via_getitem (self):%0A        assert_that(calling(lambda x: x%5B%22fake%22%5D).with_args(self.xmp),%0A                    raises(KeyError))
 %0A   
@@ -1422,36 +1422,38 @@
 ng(lambda x: x%5B%22
-fake
+bbbbbb
 %22%5D).with_args(se

Refactor namespaces into test class variable