Пример #1
0
def test_Options_clone():
    opt = Options((x, y, z), {'domain': 'ZZ'})

    assert opt.gens == (x, y, z)
    assert opt.domain == ZZ
    assert ('order' in opt) is False

    new_opt = opt.clone({'gens': (x, y), 'order': 'lex'})

    assert opt.gens == (x, y, z)
    assert opt.domain == ZZ
    assert ('order' in opt) is False

    assert new_opt.gens == (x, y)
    assert new_opt.domain == ZZ
    assert ('order' in new_opt) is True
Пример #2
0
def test_Options_clone():
    opt = Options((x, y, z), {'domain': 'ZZ'})

    assert opt.gens == (x, y, z)
    assert opt.domain == ZZ
    assert ('order' in opt) is False
    assert opt.args == {'domain': ZZ}

    # defaults:
    assert opt.flags['all'] is False
    assert opt.flags['include'] is False
    assert opt.options['strict'] is True

    new_opt = opt.clone({'gens': (x, y), 'order': 'lex'})

    assert opt.gens == (x, y, z)
    assert opt.domain == ZZ
    assert ('order' in opt) is False

    assert new_opt.gens == (x, y)
    assert new_opt.domain == ZZ
    assert ('order' in new_opt) is True

    opt.spam = 'eggs'
    assert opt.spam == 'eggs'

    class SpamOpt(BooleanOption, metaclass=OptionType):
        option = 'spam'
        before = ['gens']
        after = ['domain']

    Options.__order__ = None
    pytest.raises(RuntimeError, lambda: Options._init_dependencies_order())
    delattr(Options, 'spam')
    del Options.__options__['spam']
    Options.__order__ = None
    Options._init_dependencies_order()
    Options._init_dependencies_order()  # noop

    pytest.raises(OptionError, lambda: Options((x,), {'gens': (x, y)}))
    pytest.raises(OptionError, lambda: Options((x,), {'spam': 1}))
    pytest.raises(OptionError, lambda: Options((x,), {'field': True,
                                                      'gaussian': True}))
    pytest.raises(OptionError, lambda: Options((x,), {'gen': x}, strict=True))
Пример #3
0
def test_pickling_polys_options():
    for c in (Options, Options((), {'domain': 'ZZ', 'polys': False})):
        check(c)
Пример #4
0
def test_pickling_polys_options():
    for c in (Options, Options((), dict(domain='ZZ', polys=False))):
        check(c)
Пример #5
0
def test_Options_clone():
    opt = Options((x, y, z), {'domain': 'ZZ'})

    assert opt.gens == (x, y, z)
    assert opt.domain == ZZ
    assert ('order' in opt) is False
    assert opt.args == {'domain': ZZ}

    # defaults:
    assert opt.flags['all'] is False
    assert opt.flags['include'] is False
    assert opt.options['strict'] is True

    new_opt = opt.clone({'gens': (x, y), 'order': 'lex'})

    assert opt.gens == (x, y, z)
    assert opt.domain == ZZ
    assert ('order' in opt) is False

    assert new_opt.gens == (x, y)
    assert new_opt.domain == ZZ
    assert ('order' in new_opt) is True

    opt.spam = 'eggs'
    assert opt.spam == 'eggs'

    class SpamOpt(BooleanOption, metaclass=OptionType):
        option = 'spam'
        before = ['gens']
        after = ['domain']

    Options.__order__ = None
    pytest.raises(RuntimeError, lambda: Options._init_dependencies_order())
    delattr(Options, 'spam')
    del Options.__options__['spam']
    Options.__order__ = None
    Options._init_dependencies_order()
    Options._init_dependencies_order()  # noop

    pytest.raises(OptionError, lambda: Options((x, ), {'gens': (x, y)}))
    pytest.raises(OptionError, lambda: Options((x, ), {'spam': 1}))
    pytest.raises(OptionError, lambda: Options((x, ), {
        'field': True,
        'gaussian': True
    }))
    pytest.raises(OptionError, lambda: Options((x, ), {'gen': x}, strict=True))