import pint
import pytest

from nxtomo.nxobject.nxbeam import NXbeam

ureg = pint.get_application_registry()


def test_nx_beam():
    """Test creation and saving of an NXbeam."""
    nx_beam = NXbeam()

    with pytest.raises(TypeError):
        nx_beam.incident_energy = "tata"
    nx_beam.incident_energy = 1.02 * ureg.keV

    assert nx_beam.incident_energy.magnitude == 1.02

    # Test some concatenation
    nx_beam_concatenate = NXbeam.concatenate([nx_beam, nx_beam])
    assert nx_beam_concatenate.incident_energy.magnitude == 1.02
