示例#1
0
def test_nosymada():
  from pylada.dftcrystal.properties import Properties
  a = Properties()
  assert a.nosymada is None
  assert len(a.output_map()) == 0
  a.nosymada = True
  assert a.print_input() == "NOSYMADA\nEND\n"
示例#2
0
def test_rdfmwf():
  from collections import namedtuple
  from shutil import rmtree
  from tempfile import mkdtemp
  from os.path import join, exists
  from os import remove
  from pylada.dftcrystal.properties import Properties
  from pylada.error import IOError

  Extract = namedtuple('Extract', ['directory'])
  try: 
    indir = mkdtemp()
    outdir = mkdtemp()

    extract = Extract(indir)
    a = Properties(input=extract)
    assert a.rdfmwf is None
    assert len(a.output_map(filework=False)) == 0
    assert len(a.print_input(filework=False)) == 0
    try: a.output_map(filework=True, workdir=outdir)
    except IOError: pass
    else: raise Exception()

    a.rdfmwf = True
    assert len(a.output_map(filework=False)) == 1
    assert a.output_map(filework=False)['rdfmwf'] == True
    try: a.output_map(filework=True, workdir=outdir)
    except IOError: pass
    else: raise Exception()

    a.rdfmwf = False
    assert len(a.output_map(filework=False)) == 0
    try: a.output_map(filework=True, workdir=outdir)
    except IOError: pass
    else: raise Exception()

    # now with .f98 file
    with open(join(indir, 'crystal.f98'), 'w') as file: file.write('hello')
    a.rdfmwf = None
    assert len(a.output_map(filework=False)) == 1
    assert a.output_map(filework=False)['rdfmwf'] == True
    assert not exists(join(outdir, 'fort.98'))
    # should fail
    a.rdfmwf = False
    try: a.output_map(filework=True, workdir=outdir)
    except IOError: pass
    else: raise Exception()
    # now check writing
    a.rdfmwf = None
    assert not exists(join(outdir, 'fort.98'))
    assert a.output_map(filework=True, workdir=outdir)['rdfmwf'] == True
    assert exists(join(outdir, 'fort.98'))
    remove(join(outdir, 'fort.98'))
    a.rdfmwf = True
    assert not exists(join(outdir, 'fort.98'))
    assert a.output_map(filework=True, workdir=outdir)['rdfmwf'] == True
    assert exists(join(outdir, 'fort.98'))
    remove(join(indir, 'crystal.f98'))
    remove(join(outdir, 'fort.98'))
    with open(join(outdir, 'crystal.f98'), 'w') as file: file.write('hello')
    assert exists(join(outdir, 'crystal.f98'))
    assert not exists(join(outdir, 'fort.98'))
    assert a.output_map(filework=True, workdir=outdir, outdir=outdir)['rdfmwf'] == True
    assert exists(join(outdir, 'fort.98'))
    remove(join(outdir, 'fort.98'))
    
    # now for .f9
    with open(join(indir, 'crystal.f9'), 'w') as file: file.write('hello')
    a.rdfmwf = None
    assert len(a.output_map(filework=False)) == 0
    assert not exists(join(outdir, 'fort.9'))
    # should fail
    a.rdfmwf = True
    try: a.output_map(filework=True, workdir=outdir)
    except IOError: pass
    else: raise Exception()
    # now check writing
    a.rdfmwf = None
    assert not exists(join(outdir, 'fort.9'))
    assert len(a.output_map(filework=True, workdir=outdir)) == 0
    assert exists(join(outdir, 'fort.9'))
    remove(join(outdir, 'fort.9'))
    a.rdfmwf = False
    assert not exists(join(outdir, 'fort.9'))
    assert len(a.output_map(filework=True, workdir=outdir)) == 0
    assert exists(join(outdir, 'fort.9'))
    remove(join(indir, 'crystal.f9'))
    remove(join(outdir, 'fort.9'))
    with open(join(outdir, 'crystal.f9'), 'w') as file: file.write('hello')
    assert not exists(join(outdir, 'fort.9'))
    assert exists(join(outdir, 'crystal.f9'))
    assert len(a.output_map(filework=True, workdir=outdir, outdir=outdir)) == 0
    assert exists(join(outdir, 'fort.9'))
    remove(join(outdir, 'fort.9'))

  finally:
    try: rmtree(indir)
    except: pass
    try: rmtree(outdir)
    except: pass