Skip to content

Commit

Permalink
Merge branch 'martinal/topic-unicode-preparations'
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Sandve Alnæs committed Oct 12, 2016
2 parents b98bf5e + 6b4cd94 commit eca3520
Show file tree
Hide file tree
Showing 90 changed files with 1,587 additions and 1,584 deletions.
10 changes: 4 additions & 6 deletions demo/Poisson.ufl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2004-2008 Anders Logg
#
# This file is part of UFL.
Expand All @@ -15,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with UFL. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Martin Sandve Alnes, 2009
# Modified by Martin Sandve Alnæs, 2009
#
# Last changed: 2009-03-02
#
Expand All @@ -27,8 +28,5 @@ u = TrialFunction(element)
v = TestFunction(element)
f = Coefficient(element)

dx0_1 = dx(0, {"quadrature_order": 1})
dx0_2 = dx(0, {"quadrature_order": 2})

a = dot(grad(v), grad(u))*dx0_1
L = v*f*dx0_2
a = dot(grad(v), grad(u))*dx(degree=1)
L = v*f*dx(degree=2)
7 changes: 5 additions & 2 deletions scripts/ufl-analyse
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __date__ = "2008-05-09"
# Modified by Anders Logg, 2009.
# Last changed: 2015-01-05

import io
import sys, optparse
from ufl.log import warning
from ufl.algorithms import load_ufl_file, validate_form, ufl2latex, tree_format
Expand Down Expand Up @@ -53,7 +54,9 @@ for filename in filenames:
# checks while the form is being built
print("Loading form file '%s'" % filename)
try:
# TODO: Forms that fail will usually fail inside this, which doesn't produce any log... Perhaps we should pass a log file to load_forms?
# TODO: Forms that fail will usually fail inside this,
# which doesn't produce any log...
# Perhaps we should pass a log file to load_forms?
data = load_ufl_file(filename)
forms = data.forms
except:
Expand All @@ -62,7 +65,7 @@ for filename in filenames:

outputfilename = filename + ".log"
if write_file:
outputfile = open(outputfilename, "w")
outputfile = io.open(outputfilename, "w", encoding="utf-8")

def write(*items):
text = " ".join(str(s) for s in items)
Expand Down
16 changes: 12 additions & 4 deletions scripts/ufl-convert
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from __future__ import print_function

import sys
import subprocess
import io
import os
import optparse
from pprint import pprint
Expand All @@ -13,15 +15,21 @@ from ufl.algorithms.formfiles import load_ufl_file

# --- Utilities

# Taken from http://ivory.idyll.org/blog/mar-07/replacing-commands-with-subprocess
from subprocess import Popen, PIPE, STDOUT

def get_status_output(cmd, input=None, cwd=None, env=None):
pipe = Popen(cmd, shell=True, cwd=cwd, env=env, stdout=PIPE, stderr=STDOUT)
"""Replacement for commands.getstatusoutput which does not work on Windows (or Python 3)."""
if isinstance(cmd, string_types):
cmd = cmd.strip().split()
pipe = subprocess.Popen(cmd, shell=False, cwd=cwd, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(output, errout) = pipe.communicate(input=input)
assert not errout
status = pipe.returncode
if isinstance(output, bytes):
output = output.decode('utf-8')
return (status, output)


def runcmd(cmd):
status, output = get_status_output(cmd)
if status != 0:
Expand All @@ -31,7 +39,7 @@ def runcmd(cmd):

def write_file(filename, text):
"Write text to a file and close it."
with open(filename, "w") as f:
with io.open(filename, "w", encoding="utf-8") as f:
f.write(text)
print("Wrote file %s" % filename)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
ignore = E501,E226
ignore = E501,E226,W503,E127,E123,E128,E265
exclude = .git,__pycache__,doc/sphinx/source/conf.py,build,dist,test
5 changes: 0 additions & 5 deletions test/sourceme.sh

This file was deleted.

72 changes: 14 additions & 58 deletions test/test_analyse_demos.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,31 @@
# -*- coding: utf-8 -*-

from __future__ import print_function

__authors__ = "Martin Sandve Alnæs"
__date__ = "2008-09-28 -- 2008-09-28"

import os
import pytest
from ufl.algorithms import load_ufl_file, validate_form
from ufl.algorithms import load_ufl_file, compute_form_data, validate_form
from glob import glob

# Taken from
# http://ivory.idyll.org/blog/mar-07/replacing-commands-with-subprocess
from subprocess import Popen, PIPE, STDOUT


def get_status_output(cmd, input=None, cwd=None, env=None):
pipe = Popen(cmd, shell=True, cwd=cwd, env=env, stdout=PIPE, stderr=STDOUT)
(output, errout) = pipe.communicate(input=input)
assert not errout
status = pipe.returncode
return (status, output)


def _test_all_demos():
# Check all at once
skip = set(glob("../demo/_*.ufl"))
filenames = [f for f in sorted(glob("../demo/*.ufl")) if not f in skip]
cmd = "ufl-analyse %s" % " ".join(filenames)
status, output = get_status_output(cmd)
assert status == 0
demodir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "demo"))


def get_demo_filenames():
skiplist = glob("../demo/_*.ufl") # + ["../demo/Hyperelasticity3D.ufl"]
filenames = []
for f in sorted(glob("../demo/*.ufl")):
if f in skiplist:
print(("Skipping demo %s" % f))
else:
filenames.append(f)
filenames = sorted(
set(glob(os.path.join(demodir, "*.ufl")))
- set(glob(os.path.join(demodir, "_*.ufl")))
)
return filenames


def xtest_each_demo_with_ufl_analyse():
"Check each file from cmdline with ufl-analyse."
for f in get_demo_filenames():
cmd = "ufl-analyse %s" % f
status, output = get_status_output(cmd)
assert status == 0
if status == 0:
print(("Successfully analysed %s without problems" % f))
else:
name = "%s.analysis" % f
print(("Encountered problems when analysing %s "
"(return code %s), see output in file %s" % (f, status, name)))
of = open(name, "w")
of.write(output)
of.close()
print()
print(output)
print()


def test_each_demo_with_validate_form():
@pytest.mark.parametrize("filename", get_demo_filenames())
def test_demo_files(filename):
"Check each form in each file with validate_form."
for filename in get_demo_filenames():
print(filename)
data = load_ufl_file(filename)
for form in data.forms:
try:
validate_form(form)
excepted = 0
except:
excepted = 1
assert excepted == 0, filename
data = load_ufl_file(filename)
for form in data.forms:
#fd = compute_form_data(form) # TODO: Skip failure examples
validate_form(form)
1 change: 0 additions & 1 deletion test/test_change_to_reference_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from six.moves import xrange as range
from ufl.log import error, warning
from ufl.assertions import ufl_assert
from ufl.core.multiindex import Index, indices
from ufl.corealg.multifunction import MultiFunction
Expand Down
18 changes: 2 additions & 16 deletions test/test_derivative.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env py.test
# -*- coding: utf-8 -*-

from __future__ import print_function

__authors__ = "Martin Sandve Alnæs"
__date__ = "2009-02-17 -- 2009-02-17"

Expand Down Expand Up @@ -523,22 +525,6 @@ def test_vector_coefficient_derivatives_of_product(self):
fd = compute_form_data(J)
actual = fd.preprocessed_form.integrals()[0].integrand()

# Keeping this snippet here for a while for debugging purposes
if 0:
print(('\n', 'str:'))
print((str(actual)))
print((str(expected)))
print(('\n', 'repr:'))
print((repr(actual)))
print((repr(expected)))
from ufl.algorithms import tree_format
open('actual.txt', 'w').write(tree_format(actual))
open('expected.txt', 'w').write(tree_format(expected))
print(('\n', 'equal:'))
print((str(actual) == str(expected)))
print((repr(actual) == repr(expected)))
print((actual == expected))

# Tricky case! These are equal in representation except
# that the outermost sum/indexsum are swapped.
# Sampling the expressions instead of comparing representations.
Expand Down
12 changes: 6 additions & 6 deletions test/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ def test_annotated_literals():
assert z.ufl_shape == ()
assert z.ufl_free_indices == ()
assert z.ufl_index_dimensions == ()
assert z.free_indices() == () # Deprecated interface
assert z.index_dimensions() == {} # Deprecated interface
#assert z.free_indices() == () # Deprecated interface
#assert z.index_dimensions() == {} # Deprecated interface

z = Zero((3,))
assert z.ufl_shape == (3,)
assert z.ufl_free_indices == ()
assert z.ufl_index_dimensions == ()
assert z.free_indices() == () # Deprecated interface
assert z.index_dimensions() == {} # Deprecated interface
#assert z.free_indices() == () # Deprecated interface
#assert z.index_dimensions() == {} # Deprecated interface

i = Index(count=2)
j = Index(count=4)
# z = Zero((), (2, 4), (3, 5))
z = Zero((), (j, i), {i: 3, j: 5})
assert z.ufl_shape == ()
assert z.free_indices() == (i, j) # Deprecated interface
assert z.index_dimensions() == {i: 3, j: 5} # Deprecated interface
#assert z.free_indices() == (i, j) # Deprecated interface
#assert z.index_dimensions() == {i: 3, j: 5} # Deprecated interface
assert z.ufl_free_indices == (2, 4)
assert z.ufl_index_dimensions == (3, 5)

Expand Down
80 changes: 0 additions & 80 deletions test/test_mock_expr.py

This file was deleted.

0 comments on commit eca3520

Please sign in to comment.