Esempio n. 1
0
    def test_copy_container_with_token(self):
        jcont = JSONContainer(ARRAY)
        dcc_tokens = [(dcc, token) for dcc, token in jcont.iter_bound_tokens()]

        dc, token = dcc_tokens[0]
        self.assertIsNotNone(dc.get_token())

        dc_copy = copy.deepcopy(dc)
        self.assertIsNotNone(dc_copy.get_token())
Esempio n. 2
0
    def test_copy_container_with_token(self):
        jcont = JSONContainer(ARRAY)
        dcc_tokens = [(dcc, token) for dcc, token in jcont.iter_bound_tokens()]

        dc, token = dcc_tokens[0]
        self.assertIsNotNone(dc.get_token())

        dc_copy = copy.deepcopy(dc)
        self.assertIsNotNone(dc_copy.get_token())
Esempio n. 3
0
    def test_iter_bound_tokens_array(self):
        jcont = JSONContainer(ARRAY)
        dcc_tokens = [(dcc, token) for dcc, token in jcont.iter_bound_tokens()]

        for dcc, token in dcc_tokens:
            self.assertIsInstance(dcc, JSONContainer)
            self.assertIsInstance(token, DataToken)
            self.assertIs(token, dcc.token)

        EXPECTED_TOKENS = [('list-0-string', 'abc')]
        token_data = [(t.get_name(), t.get_value()) for dcc, t in dcc_tokens]
        self.assertEqual(EXPECTED_TOKENS, token_data)
Esempio n. 4
0
    def test_iter_bound_tokens_array(self):
        jcont = JSONContainer(ARRAY)
        dcc_tokens = [(dcc, token) for dcc, token in jcont.iter_bound_tokens()]

        for dcc, token in dcc_tokens:
            self.assertIsInstance(dcc, JSONContainer)
            self.assertIsInstance(token, DataToken)
            self.assertIs(token, dcc.token)

        EXPECTED_TOKENS = [('list-0-string', 'abc')]
        token_data = [(t.get_name(), t.get_value()) for dcc, t in dcc_tokens]
        self.assertEqual(EXPECTED_TOKENS, token_data)
Esempio n. 5
0
    def test_object_null_value(self):
        jcont = JSONContainer(OBJECT_NULL)
        dcc_tokens = [(dcc, token) for dcc, token in jcont.iter_bound_tokens()]

        for dcc, token in dcc_tokens:
            self.assertIsInstance(dcc, JSONContainer)
            self.assertIsInstance(token, DataToken)
            self.assertIs(token, dcc.token)

        EXPECTED_TOKENS = [('object-key-null', None)]
        token_data = [(t.get_name(), t.get_value()) for dcc, t in dcc_tokens]
        self.assertEqual(EXPECTED_TOKENS, token_data)
Esempio n. 6
0
    def test_basic(self):
        jcont = JSONContainer(COMPLEX_OBJECT)
        dcc_tokens = [(dcc, token) for dcc, token in jcont.iter_bound_tokens()]

        for dcc, token in dcc_tokens:
            self.assertIsInstance(dcc, JSONContainer)
            self.assertIsInstance(token, DataToken)
            self.assertIs(token, dcc.token)

        EXPECTED_TOKENS = [('object-second_key-list-0-string', 'abc'),
                           ('object-key-string', 'value')]
        token_data = [(t.get_name(), t.get_value()) for dcc, t in dcc_tokens]
        self.assertEqual(EXPECTED_TOKENS, token_data)
Esempio n. 7
0
    def test_basic(self):
        jcont = JSONContainer(COMPLEX_OBJECT)
        dcc_tokens = [(dcc, token) for dcc, token in jcont.iter_bound_tokens()]

        for dcc, token in dcc_tokens:
            self.assertIsInstance(dcc, JSONContainer)
            self.assertIsInstance(token, DataToken)
            self.assertIs(token, dcc.token)

        EXPECTED_TOKENS = [('object-second_key-list-0-string', 'abc'),
                           ('object-key-string', 'value')]
        token_data = [(t.get_name(), t.get_value()) for dcc, t in dcc_tokens]
        self.assertEqual(EXPECTED_TOKENS, token_data)
Esempio n. 8
0
    def test_iter_bound_tokens_modify_during_iter(self):
        jcont = JSONContainer(ARRAY)
        idx = None
        tokens = []

        for idx, (dcc, token) in enumerate(jcont.iter_bound_tokens()):
            self.assertIsInstance(dcc, JSONContainer)
            self.assertIsInstance(token, DataToken)
            self.assertIs(token, dcc.token)

            token.set_value('xyz')
            tokens.append(token)

        self.assertEqual(idx, 0)

        EXPECTED_TOKENS = [('list-0-string', 'xyz')]
        token_data = [(t.get_name(), t.get_value()) for t in tokens]

        self.assertEqual(EXPECTED_TOKENS, token_data)
        self.assertEqual(str(dcc), ARRAY.replace('abc', 'xyz'))
Esempio n. 9
0
    def test_iter_bound_tokens_modify_during_iter(self):
        jcont = JSONContainer(ARRAY)
        idx = None
        tokens = []

        for idx, (dcc, token) in enumerate(jcont.iter_bound_tokens()):
            self.assertIsInstance(dcc, JSONContainer)
            self.assertIsInstance(token, DataToken)
            self.assertIs(token, dcc.token)

            token.set_value('xyz')
            tokens.append(token)

        self.assertEqual(idx, 0)

        EXPECTED_TOKENS = [('list-0-string', 'xyz')]
        token_data = [(t.get_name(), t.get_value()) for t in tokens]

        self.assertEqual(EXPECTED_TOKENS, token_data)
        self.assertEqual(str(dcc), ARRAY.replace('abc', 'xyz'))