コード例 #1
0
def test_truediv():
    assert Node(model, 'functions')/'step' == Node(model, 'functions/step')
    with logging_disabled():
        try:
            Node(model, 'functions')/False
        except TypeError:
            pass
コード例 #2
0
def test_tag():
    assert Node(model, 'functions/step').tag() == 'step1'
    if not client.port:
        # Skip test in client-server mode where it's fairly slow.
        here = Path(__file__).resolve().parent
        demo = client.load(here.parent/'demos'/'capacitor.mph')
        demo.solve()
        root = Node(model, '')
        compare_tags(root, demo)
コード例 #3
0
def test_init():
    node = Node(model, '')
    assert node.model == model
    node = Node(model, 'functions')
    assert node.model == model
    assert 'function' in node.alias
    assert 'functions' in node.alias.values()
    assert 'functions' in node.groups
    assert 'self.model.java.func()' in node.groups.values()
    Node(model, node)
    with logging_disabled():
        try:
            Node(model, False)
        except TypeError:
            pass
コード例 #4
0
def test_toggle():
    node = Node(model, 'functions/step')
    assert node.java.isActive()
    node.toggle()
    assert not node.java.isActive()
    node.toggle()
    assert node.java.isActive()
    node.toggle('off')
    assert not node.java.isActive()
    node.toggle('on')
    assert node.java.isActive()
    assert not Node(model, 'functions/non-existing').exists()
    with logging_disabled():
        try:
            Node(model, 'functions/non-existing').toggle()
        except LookupError:
            pass
コード例 #5
0
def test_properties():
    assert Node(model, 'functions').properties() == {}
    function = Node(model, 'functions/step')
    assert 'funcname' in function.properties()
    assert 'funcname' in function.properties().keys()
    assert 'step' in function.properties().values()
    assert ('funcname', 'step') in function.properties().items()
コード例 #6
0
def test_retag():
    with logging_disabled():
        try:
            Node(model, '').retag('something')
        except PermissionError:
            pass
        try:
            Node(model, 'functions').retag('something')
        except PermissionError:
            pass
        try:
            Node(model, 'functions/non-existing').retag('something')
        except Exception:
            pass
    node = Node(model, 'functions/step')
    old = node.tag()
    node.retag('new')
    assert node.tag() == 'new'
    node.retag(old)
    assert node.tag() == old
コード例 #7
0
def test_remove():
    functions = Node(model, 'functions')
    assert (functions/'Analytic 1').exists()
    (functions/'Analytic 1').remove()
    assert not (functions/'Analytic 1').exists()
    assert (functions/'f').exists()
    (functions/'f').remove()
    assert not (functions/'f').exists()
    physics = Node(model, 'physics')
    (physics/'Electrostatics 1').remove()
    assert not (physics/'Electrostatics 1').exists()
    with logging_disabled():
        try:
            Node(model, '').remove()
        except PermissionError:
            pass
        try:
            Node(model, 'function').remove()
        except PermissionError:
            pass
        try:
            Node(model, 'function/non-existing').remove()
        except LookupError:
            pass
コード例 #8
0
def test_run():
    study = Node(model, 'studies/static')
    solution = Node(model, 'solutions/electrostatic solution')
    assert solution.java.isEmpty()
    study.run()
    assert not solution.java.isEmpty()
    with logging_disabled():
        try:
            Node(model, 'functions/non-existing').run()
        except LookupError:
            pass
        try:
            Node(model, 'functions').run()
        except RuntimeError:
            pass
コード例 #9
0
def test_rename():
    with logging_disabled():
        try:
            Node(model, '').rename('something')
        except PermissionError:
            pass
        try:
            Node(model, 'functions').rename('something')
        except PermissionError:
            pass
    node = Node(model, 'functions/step')
    name = node.name()
    renamed = Node(model, 'functions/renamed')
    assert not renamed.exists()
    node.rename('renamed')
    assert node.exists()
    assert renamed.exists()
    node.rename(name)
    assert node.exists()
    assert not renamed.exists()
コード例 #10
0
def test_iter():
    assert Node(model, 'functions/step')  in list(Node(model, 'functions'))
コード例 #11
0
def test_contains():
    assert 'step' in Node(model, 'functions')
    assert 'other' not in Node(model, 'functions')
    assert Node(model, 'functions/step') in Node(model, 'functions')
    assert Node(model, 'functions/other') not in Node(model, 'functions')
コード例 #12
0
def test_parent():
    assert Node(model, '').parent() is None
    assert Node(model, 'functions/step').parent() == Node(model, 'functions')
コード例 #13
0
def test_eq():
    assert Node(model, 'function/step') == Node(model, '/functions/step/')
コード例 #14
0
def test_repr():
    assert repr(Node(model, 'functions/step')) == "Node('functions/step')"
コード例 #15
0
def test_str():
    assert str(Node(model, 'functions/step')) == 'functions/step'
コード例 #16
0
def test_property():
    root     = Node(model, '')
    function = root/'functions'/'step'
    axis     = root/'geometries'/'geometry'/'axis'
    material = root/'materials'/'medium 1'
    plot     = root/'plots'/'evolution'
    export   = root/'exports'/'data'
    # Test conversion to and from 'Boolean'.
    old = function.property('smoothactive')
    function.property('smoothactive', False)
    assert function.property('smoothactive') is False
    function.property('smoothactive', old)
    assert function.property('smoothactive') == old
    # Test conversion to and from 'Double'.
    old = function.property('location')
    function.property('location', -10.0)
    assert isclose(function.property('location'), -10)
    function.property('location', old)
    assert isclose(function.property('location'), old)
    # Test conversion to and from 'DoubleArray'.
    old = export.property('outersolnumindices')
    new = array([1.0, 2.0, 3.0])
    export.property('outersolnumindices', new)
    assert isclose(export.property('outersolnumindices'), new).all()
    export.property('outersolnumindices', old)
    assert isclose(export.property('outersolnumindices'), old).all()
    # Test conversion to and from 'File'.
    old = export.property('filename')
    export.property('filename', Path('new.tif'))
    assert export.property('filename') == Path('new.tif')
    export.property('filename', old)
    assert export.property('filename') == old
    # Test conversion to and from 'Int'.
    old = plot.property('axisprecision')
    plot.property('axisprecision', 4)
    assert plot.property('axisprecision') == 4
    plot.property('axisprecision', old)
    assert plot.property('axisprecision') == old
    # Test conversion to and from 'IntArray'.
    old = axis.property('segid')
    new = array([1, 2, 3], dtype=int)
    axis.property('segid', new)
    assert (axis.property('segid') == new).all()
    axis.property('segid', old)
    assert (axis.property('segid') == old).all()
    # Test conversion from 'None'.
    assert material.property('customize') is None
    # Test conversion to and from 'String'.
    old = function.property('funcname')
    function.property('funcname', 'new')
    assert function.property('funcname') == 'new'
    function.property('funcname', old)
    assert function.property('funcname') == old
    # Test conversion to and from 'StringArray'.
    old = export.property('descr')
    export.property('descr', ['x', 'y', 'z'])
    assert export.property('descr') == ['x', 'y', 'z']
    export.property('descr', old)
    assert export.property('descr') == old
    # Test conversion to and from 'StringMatrix'.
    old = plot.property('plotonsecyaxis')
    new = [['medium 1', 'on', 'ptgr1'], ['medium 2', 'on', 'ptgr2']]
    plot.property('plotonsecyaxis', new)
    assert plot.property('plotonsecyaxis') == new
    plot.property('plotonsecyaxis', old)
    assert plot.property('plotonsecyaxis') == old
    # Read and write back every node property in the model.
    if not client.port:
        # Skip test in client-server mode where it's excruciatingly slow.
        rewrite_properties(root)
コード例 #17
0
def test_children():
    assert Node(model, 'functions/step') in Node(model, 'functions').children()
    datasets = Node(model, 'datasets').children()
    assert Node(model, 'datasets/sweep//solution') in datasets
    assert Node(model, 'datasets/sweep//solution').exists()
    assert not Node(model, 'datasets/sweep/solution').exists()
コード例 #18
0
def test_is_root():
    assert Node(model, None).is_root()
    assert Node(model, '').is_root()
    assert Node(model, '/').is_root()
コード例 #19
0
def test_create():
    functions = Node(model, 'functions')
    functions.create('Analytic')
    assert (functions/'Analytic 1').exists()
    functions.create('Analytic', name='f')
    assert (functions/'f').exists()
    geometry = Node(model, 'geometries/geometry')
    physics = Node(model, 'physics')
    physics.create('Electrostatics', geometry)
    with logging_disabled():
        try:
            Node(model, '').create()
        except PermissionError:
            pass
        try:
            Node(model, 'components/component').create()
        except RuntimeError:
            pass
コード例 #20
0
def test_type():
    assert Node(model, 'functions/step').type() == 'Step'
コード例 #21
0
def test_is_group():
    assert Node(model, 'functions').is_group()
コード例 #22
0
def test_exists():
    assert Node(model, 'functions').exists()
    assert Node(model, 'functions/step').exists()
    assert not Node(model, 'functions/new').exists()
コード例 #23
0
def test_java():
    assert Node(model, 'functions').java
    assert Node(model, 'functions/step').java
コード例 #24
0
def test_name():
    assert Node(model, 'functions').name() == 'functions'
    assert Node(model, 'functions/step').name() == 'step'
コード例 #25
0
def test_inspect():
    node = Node(model, 'datasets/sweep//solution')
    node.toggle('off')
    with capture_stdout() as output:
        mph.inspect(node)
    assert output.text().strip().startswith('name:')