import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
sys.path.append(root)

# ----------------------------------------------------------------------------

# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

# ----------------------------------------------------------------------------
# -*- coding: utf-8 -*-

import ccxt  # noqa: F402

def test_extend():
    exchange = ccxt.Exchange({
        'id': 'regirock',
    })
    obj1 = {
        'a': 1,
        'b': [1, 2],
        'c': [{
    'test1': 1,
    'test2': 1,
}],
        'd': None,
        'e': 'not_undefined',
        'sub': {
            'a': 1,
            'b': [1, 2],
            'c': [{
    'test1': 1,
    'test2': 2,
}],
            'd': None,
            'e': 'not_undefined',
            'other1': 'x',
        },
        'other1': 'x',
    }
    obj2 = {
        'a': 2,
        'b': [3, 4],
        'c': [{
    'test1': 2,
    'test3': 3,
}],
        'd': 'not_undefined',
        'e': None,
        'sub': {
            'a': 2,
            'b': [3, 4],
            'c': [{
    'test1': 2,
    'test3': 3,
}],
            'd': 'not_undefined',
            'e': None,
            'other2': 'y',
        },
        'other2': 'y',
    }
    # extend
    extended = exchange.extend(obj1, obj2)
    tbfe_check_extended(extended, True)


def tbfe_check_extended(extended, has_sub):
    assert extended['a'] == 2
    assert extended['b'][0] == 3
    assert extended['b'][1] == 4
    assert extended['c'][0]['test1'] == 2
    assert not ('test2' in extended['c'][0])
    assert extended['c'][0]['test3'] == 3
    assert extended['d'] == 'not_undefined'
    assert extended['e'] is None
    assert extended['other1'] == 'x'
    assert extended['other2'] == 'y'
    if has_sub:
        assert 'sub' in extended
