import importlib

variant_module = importlib.import_module("@MODNAME@")
V1 = variant_module.V1
V2 = variant_module.V2
VariantHolder = variant_module.VariantHolder
VariantNoneHolder = variant_module.VariantNoneHolder
VariantArithmeticHolder = variant_module.VariantArithmeticHolder
make_variant = variant_module.make_variant
make_variant_none = variant_module.make_variant_none
make_variant_arithmetic = variant_module.make_variant_arithmetic

variant = make_variant()
assert isinstance(variant, V1)

v1 = V1()
v1.v = 10

v2 = V2()
v2.v = "c"

variant_holder = VariantHolder()

# Test copy from variant alternative V1 to non initialized variant
variant_holder.variant = v1
assert isinstance(variant_holder.variant, V1)
assert variant_holder.variant.v == v1.v

# variant_holder.variant is a copy of v1
variant_holder.variant.v = 11
assert v1.v != variant_holder.variant.v

# Test variant_holder.variant return by reference
# v1 reference variant_holder.variant
v1 = variant_holder.variant
variant_holder.variant.v = 100
assert variant_holder.variant.v == 100
assert v1.v == 100
v1.v = 1000
assert variant_holder.variant.v == 1000
assert v1.v == 1000

# Test with the second alternative type
variant_holder.variant = v2
assert isinstance(variant_holder.variant, V2)
assert variant_holder.variant.v == v2.v

# Test variant that hold a None value
v_none = make_variant_none()
assert v_none is None

variant_none_holder = VariantNoneHolder()
v_none = variant_none_holder.variant
assert v_none is None

v1 = V1()
v1.v = 1
variant_none_holder.variant = v1
assert variant_none_holder.variant.v == 1
v1 = variant_none_holder.variant
v1.v = 10
assert variant_none_holder.variant.v == 10
# variant_none_holder.variant = None


# Test variant that hold base type
v_arithmetic = make_variant_arithmetic()
assert isinstance(v_arithmetic, int)

variant_arithemtic_holder = VariantArithmeticHolder()
assert isinstance(variant_arithemtic_holder.variant, int)
variant_arithemtic_holder.variant = 2.0
assert variant_arithemtic_holder.variant == 2
assert isinstance(variant_arithemtic_holder.variant, float)
# Arithmetic type doesn't support reference
v1 = variant_arithemtic_holder.variant
v1 = 3
assert variant_arithemtic_holder.variant != v1
