class TestNestedExample(unittest.TestCase):
    """Quick integration test using nested RepeatingContainers."""

    def setUp(self):
        self.group = RepeatingContainer([
            RepeatingContainer({'foo': 'abc', 'bar': 'def'}),
            'ghi',
        ])

    def test_method(self):
        result1, result2 = self.group.upper()
        self.assertEqual(dict(result1), {'foo': 'ABC', 'bar': 'DEF'})
        self.assertEqual(result2, 'GHI')

    def test_magic_method(self):
        result1, result2 = self.group + 'XYZ'
        self.assertEqual(dict(result1), {'foo': 'abcXYZ', 'bar': 'defXYZ'})
        self.assertEqual(result2, 'ghiXYZ')

    def test_unreflected_magic_method(self):
        result1, result2 = 'XYZ' + self.group
        self.assertEqual(dict(result1), {'foo': 'XYZabc', 'bar': 'XYZdef'})
        self.assertEqual(result2, 'XYZghi')

    def test_deeply_nested(self):
        group = RepeatingContainer([
            RepeatingContainer([
                RepeatingContainer(['abc', 'def']),
                RepeatingContainer(['abc', 'def']),
            ]),
            RepeatingContainer([
                RepeatingContainer(['abc', 'def']),
                RepeatingContainer(['abc', 'def'])
            ])
        ])

        result = group + ('xxx' + group.upper())  # <- Operate on RepeatingContainer.

        # Unpack various nested values.
        subresult1, subresult2 = result
        subresult1a, subresult1b = subresult1
        subresult2a, subresult2b = subresult2

        self.assertEqual(subresult1a._objs, ('abcxxxABC', 'defxxxDEF'))
        self.assertEqual(subresult1b._objs, ('abcxxxABC', 'defxxxDEF'))
        self.assertEqual(subresult2a._objs, ('abcxxxABC', 'defxxxDEF'))
        self.assertEqual(subresult2b._objs, ('abcxxxABC', 'defxxxDEF'))
    def test_deeply_nested(self):
        group = RepeatingContainer([
            RepeatingContainer([
                RepeatingContainer(['abc', 'def']),
                RepeatingContainer(['abc', 'def']),
            ]),
            RepeatingContainer([
                RepeatingContainer(['abc', 'def']),
                RepeatingContainer(['abc', 'def'])
            ])
        ])

        result = group + ('xxx' + group.upper())  # <- Operate on RepeatingContainer.

        # Unpack various nested values.
        subresult1, subresult2 = result
        subresult1a, subresult1b = subresult1
        subresult2a, subresult2b = subresult2

        self.assertEqual(subresult1a._objs, ('abcxxxABC', 'defxxxDEF'))
        self.assertEqual(subresult1b._objs, ('abcxxxABC', 'defxxxDEF'))
        self.assertEqual(subresult2a._objs, ('abcxxxABC', 'defxxxDEF'))
        self.assertEqual(subresult2b._objs, ('abcxxxABC', 'defxxxDEF'))
 def test__call__(self):
     group = RepeatingContainer(['foo', 'bar'])
     result = group.upper()
     self.assertIsInstance(result, RepeatingContainer)
     self.assertEqual(result._objs, ('FOO', 'BAR'))