Skip to content

Commit

Permalink
#2717: Move is_character test to datanode_test
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Oct 29, 2024
1 parent c31018b commit 5c17b4a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
30 changes: 28 additions & 2 deletions src/psyclone/tests/psyir/nodes/datanode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
# POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
# Author: A. R. Porter, STFC Daresbury Lab
# Modified J. G. Wallwork, University of Cambridge
# -----------------------------------------------------------------------------

'''Performs pytest tests on the PSyIR DataNode.
'''
from psyclone.psyir.nodes import DataNode
from psyclone.psyir.symbols import UnresolvedType
import pytest

from psyclone.psyir.nodes import DataNode, Reference
from psyclone.psyir.symbols import (CHARACTER_TYPE, DataSymbol, UnresolvedType,
INTEGER_SINGLE_TYPE, REAL_TYPE)


def test_datanode_datatype():
Expand All @@ -48,3 +52,25 @@ def test_datanode_datatype():
'''
dnode = DataNode()
assert isinstance(dnode.datatype, UnresolvedType)


def test_datanode_is_character():
'''Test that character references are marked correctly.
'''
reference = Reference(DataSymbol("char", CHARACTER_TYPE))
assert reference.is_character()

reference = Reference(DataSymbol("int", INTEGER_SINGLE_TYPE))
assert not reference.is_character()

reference = Reference(DataSymbol("real", REAL_TYPE))
assert not reference.is_character()

reference = Reference(DataSymbol("unknown", UnresolvedType()))
with pytest.raises(Exception) as excinfo:
_ = reference.is_character()
assert ("is_character could not resolve whether the expression 'unknown'"
" operates on characters." in str(excinfo.value))
reference = Reference(DataSymbol("unknown", UnresolvedType()))
assert not reference.is_character(unknown_as=False)
assert reference.is_character(unknown_as=True)
33 changes: 5 additions & 28 deletions src/psyclone/tests/psyir/nodes/reference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
# I. Kavcic, Met Office
# J. Henrichs, Bureau of Meteorology
# Modified A. B. G. Chalk, STFC Daresbury Lab
# Modified J. G. Wallwork, University of Cambridge
# -----------------------------------------------------------------------------

''' Performs py.test tests on the Reference PSyIR node. '''
Expand All @@ -46,11 +45,11 @@
from psyclone.psyGen import GenerationError
from psyclone.psyir.nodes import (ArrayReference, Assignment, colored,
KernelSchedule, Literal, Reference)
from psyclone.psyir.symbols import (ArrayType, CHARACTER_TYPE, ContainerSymbol,
DataSymbol, UnresolvedType,
ImportInterface, INTEGER_SINGLE_TYPE,
REAL_SINGLE_TYPE, REAL_TYPE, ScalarType,
Symbol, SymbolTable, UnresolvedInterface)
from psyclone.psyir.symbols import (ArrayType, ContainerSymbol, DataSymbol,
UnresolvedType, ImportInterface,
INTEGER_SINGLE_TYPE, REAL_SINGLE_TYPE,
REAL_TYPE, ScalarType, Symbol, SymbolTable,
UnresolvedInterface)


def test_reference_bad_init():
Expand Down Expand Up @@ -150,28 +149,6 @@ def test_reference_is_array():
assert ref.is_array is True


def test_reference_is_character():
'''Test that character references are marked correctly.
'''
reference = Reference(DataSymbol("char", CHARACTER_TYPE))
assert reference.is_character()

reference = Reference(DataSymbol("int", INTEGER_SINGLE_TYPE))
assert not reference.is_character()

reference = Reference(DataSymbol("real", REAL_TYPE))
assert not reference.is_character()

reference = Reference(DataSymbol("unknown", UnresolvedType()))
with pytest.raises(Exception) as excinfo:
_ = reference.is_character()
assert ("is_character could not resolve whether the expression 'unknown'"
" operates on characters." in str(excinfo.value))
reference = Reference(DataSymbol("unknown", UnresolvedType()))
assert not reference.is_character(unknown_as=False)
assert reference.is_character(unknown_as=True)


def test_reference_datatype():
'''Test the datatype property.
Expand Down

0 comments on commit 5c17b4a

Please sign in to comment.