def test_card_name_must_be_in_enum(): from traitlets import TraitError from pytest import raises card = Card("ATOMIC_SPECIES") with raises(TraitError): card.name = "nothing"
def test_goaround_subtitled(subtitled_stream): from six import StringIO card, read_card = Card('K_POINTS'), Card('K_POINTS') card.read(subtitled_stream) read_card.read(StringIO(str(card))) assert read_card.name == 'k_points' assert read_card.subtitle == 'tpiba' assert read_card.value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2"
def test_goaround(card_stream): from six import StringIO card, read_card = Card('ATOMIC_SPECIES'), Card('ATOMIC_SPECIES') card.read(card_stream) read_card.read(StringIO(str(card))) assert read_card.name == 'atomic_species' assert read_card.subtitle is None assert read_card.value == 'Al 1 this.that'
def test_goaround_subtitled(subtitled_stream): from six import StringIO card, read_card = Card("K_POINTS"), Card("K_POINTS") card.read(subtitled_stream) read_card.read(StringIO(str(card))) assert read_card.name == "k_points" assert read_card.subtitle == "tpiba" assert read_card.value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2"
def test_goaround(card_stream): from six import StringIO card, read_card = Card("ATOMIC_SPECIES"), Card("ATOMIC_SPECIES") card.read(card_stream) read_card.read(StringIO(str(card))) assert read_card.name == "atomic_species" assert read_card.subtitle is None assert read_card.value == "Al 1 this.that"
def test_read_but_not_find(subtitled_stream, card_stream): from six import StringIO card, read_card = Card('ATOMIC_SPECIES'), Card('K_POINTS') read_card.read(subtitled_stream) card.read(card_stream) read_card.read(StringIO(str(card))) assert read_card.name == 'k_points' assert read_card.subtitle == 'tpiba' assert read_card.value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2"
def test_read_but_not_find(subtitled_stream, card_stream): from six import StringIO card, read_card = Card("ATOMIC_SPECIES"), Card("K_POINTS") read_card.read(subtitled_stream) card.read(card_stream) read_card.read(StringIO(str(card))) assert read_card.name == "k_points" assert read_card.subtitle == "tpiba" assert read_card.value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2"
def test_free_cell(celldim, subtitle, expected_scale): from numpy import allclose, abs, array from pylada.espresso import Card, Namelist namelist = Namelist({'ibrav': 0}) if celldim is not None: namelist.celldm = celldim card = Card('CELL_PARAMETERS', subtitle=subtitle, value=""" 1 2 3 2 3 4 4 4 6 """) cell, scale = sh._read_free(namelist, card) assert allclose(cell, array([[1, 2, 4], [2, 3, 4], [3, 4, 6]], dtype='float64')) assert abs(scale - expected_scale) < 1e-8
def test_read_subtitled_card(subtitled_stream): card = Card('K_POINTS') card.read(subtitled_stream) assert card.name == 'k_points' assert card.subtitle == 'tpiba' assert card.value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2"
def test_read_card(card_stream): card = Card('ATOMIC_SPECIES') card.read(card_stream) assert card.name == 'atomic_species' assert card.subtitle is None assert card.value == 'Al 1 this.that'
def test_create_card_with_value_and_subtitle(): card = Card('ATOMIC_SPECIES', 'subtitle', '2') assert card.name == 'atomic_species' assert card.subtitle == '2' assert card.value == 'subtitle'
def test_create_card(): card = Card('ATOMIC_SPECIES') assert card.name == 'atomic_species' assert card.subtitle is None assert card.value is None
def test_set_card_name(): card = Card("ATOMIC_SPECIES") card.name = "k_poinTs" assert card.name == "k_points"
def test_card_name_must_be_in_enum(): from traitlets import TraitError from pytest import raises card = Card('ATOMIC_SPECIES') with raises(TraitError): card.name = 'nothing'
def test_read_subtitled_card(subtitled_stream): card = Card("K_POINTS") card.read(subtitled_stream) assert card.name == "k_points" assert card.subtitle == "tpiba" assert card.value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2"
def test_read_card(card_stream): card = Card("ATOMIC_SPECIES") card.read(card_stream) assert card.name == "atomic_species" assert card.subtitle is None assert card.value == "Al 1 this.that"
def test_allowed_card_name_dynamic_in_constructor(): card = Card('NeWnaMe') assert card.name == 'newname'
def test_set_card_name(): card = Card('ATOMIC_SPECIES') card.name = 'k_poinTs' assert card.name == 'k_points'