Skip to content

Commit

Permalink
Made changes to correct failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya2003Gupta committed Sep 1, 2023
1 parent 3d9507b commit a589890
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
21 changes: 20 additions & 1 deletion python/podio/test_MemberParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,25 @@ def test_parse_valid(self): # pylint: disable=too-many-statements
self.assertEqual(parsed.name, r'someFloat')
self.assertEqual(parsed.description, r'with an additional comment')
self.assertTrue(parsed.default_val is None)
self.assertEqual(parsed.julia_type, r'Float32')

parsed = parser.parse(r'float float2 // with numbers')
self.assertEqual(parsed.full_type, r'float')
self.assertEqual(parsed.name, r'float2')
self.assertEqual(parsed.description, r'with numbers')
self.assertEqual(parsed.julia_type, r'Float32')

parsed = parser.parse(r' float spacefloat // whitespace everywhere ')
self.assertEqual(parsed.full_type, r'float')
self.assertEqual(parsed.name, r'spacefloat')
self.assertEqual(parsed.description, 'whitespace everywhere')
self.assertEqual(parsed.julia_type, r'Float32')

parsed = parser.parse(r'int snake_case // snake case')
self.assertEqual(parsed.full_type, r'int')
self.assertEqual(parsed.name, r'snake_case')
self.assertEqual(parsed.description, r'snake case')
self.assertEqual(parsed.julia_type, r'Int32')

parsed = parser.parse(r'std::string mixed_UglyCase_12 // who wants this')
self.assertEqual(parsed.full_type, r'std::string')
Expand All @@ -48,11 +52,13 @@ def test_parse_valid(self): # pylint: disable=too-many-statements
self.assertEqual(parsed.full_type, r'unsigned long long')
self.assertEqual(parsed.name, r'uVar')
self.assertEqual(parsed.description, r'an unsigned long variable')
self.assertEqual(parsed.julia_type, r'UInt64')

parsed = parser.parse(r'unsigned int uInt // an unsigned integer')
self.assertEqual(parsed.full_type, r'unsigned int')
self.assertEqual(parsed.name, r'uInt')
self.assertEqual(parsed.description, r'an unsigned integer')
self.assertEqual(parsed.julia_type, r'UInt32')

# Fixed width integers in their various forms that they can be spelled out
# and be considered valid in our case
Expand All @@ -61,24 +67,28 @@ def test_parse_valid(self): # pylint: disable=too-many-statements
self.assertEqual(parsed.name, r'qualified')
self.assertEqual(parsed.description, r'qualified fixed width ints work')
self.assertTrue(parsed.is_builtin)
self.assertEqual(parsed.julia_type, r'Int16')

parsed = parser.parse(r'std::uint64_t bits // fixed width integer types should work')
self.assertEqual(parsed.full_type, r'std::uint64_t')
self.assertEqual(parsed.name, r'bits')
self.assertEqual(parsed.description, r'fixed width integer types should work')
self.assertTrue(parsed.is_builtin)
self.assertEqual(parsed.julia_type, r'UInt64')

parsed = parser.parse(r'int32_t fixedInt // fixed width signed integer should work')
self.assertEqual(parsed.full_type, r'std::int32_t')
self.assertEqual(parsed.name, r'fixedInt')
self.assertEqual(parsed.description, r'fixed width signed integer should work')
self.assertTrue(parsed.is_builtin)
self.assertEqual(parsed.julia_type, r'Int32')

parsed = parser.parse(r'uint16_t fixedUInt // fixed width unsigned int with 16 bits')
self.assertEqual(parsed.full_type, r'std::uint16_t')
self.assertEqual(parsed.name, r'fixedUInt')
self.assertEqual(parsed.description, r'fixed width unsigned int with 16 bits')
self.assertTrue(parsed.is_builtin)
self.assertEqual(parsed.julia_type, r'UInt16')

# an array definition with space everywhere it is allowed
parsed = parser.parse(r' std::array < double , 4 > someArray // a comment ')
Expand All @@ -90,12 +100,14 @@ def test_parse_valid(self): # pylint: disable=too-many-statements
self.assertEqual(int(parsed.array_size), 4)
self.assertEqual(parsed.array_type, r'double')
self.assertTrue(parsed.default_val is None)
self.assertEqual(parsed.julia_type, r'MVector{4, Float64}')

# an array definition as terse as possible
parsed = parser.parse(r'std::array<int,2>anArray//with a comment')
self.assertEqual(parsed.full_type, r'std::array<int, 2>')
self.assertEqual(parsed.name, r'anArray')
self.assertEqual(parsed.description, r'with a comment')
self.assertEqual(parsed.julia_type, r'MVector{2, Int32}')

parsed = parser.parse('::TopLevelNamespaceType aValidType // hopefully')
self.assertEqual(parsed.full_type, '::TopLevelNamespaceType')
Expand All @@ -108,20 +120,23 @@ def test_parse_valid(self): # pylint: disable=too-many-statements
self.assertEqual(parsed.description, r'with a top level type')
self.assertTrue(not parsed.is_builtin_array)
self.assertEqual(parsed.array_type, r'::GlobalType')
self.assertEqual(parsed.julia_type, r'MVector{1, GlobalTypeStruct}')

parsed = parser.parse(r'std::array<std::int16_t, 42> fixedWidthArray // a fixed width type array')
self.assertEqual(parsed.full_type, r'std::array<std::int16_t, 42>')
self.assertEqual(parsed.name, r'fixedWidthArray')
self.assertEqual(parsed.description, r'a fixed width type array')
self.assertTrue(parsed.is_builtin_array)
self.assertEqual(parsed.array_type, r'std::int16_t')
self.assertEqual(parsed.julia_type, r'MVector{42, Int16}')

parsed = parser.parse(r'std::array<uint32_t, 42> fixedWidthArray // a fixed width type array without namespace')
self.assertEqual(parsed.full_type, r'std::array<std::uint32_t, 42>')
self.assertEqual(parsed.name, r'fixedWidthArray')
self.assertEqual(parsed.description, r'a fixed width type array without namespace')
self.assertTrue(parsed.is_builtin_array)
self.assertEqual(parsed.array_type, r'std::uint32_t')
self.assertEqual(parsed.julia_type, r'MVector{42, UInt32}')

def test_parse_valid_default_value(self):
"""Test that member variables can be parsed correctly if they have a user
Expand Down Expand Up @@ -227,23 +242,27 @@ def test_parse_valid_no_description(self):
parsed = parser.parse('unsigned long long aLongWithoutDescription', False)
self.assertEqual(parsed.full_type, 'unsigned long long')
self.assertEqual(parsed.name, 'aLongWithoutDescription')
self.assertEqual(parsed.julia_type, r'UInt64')

parsed = parser.parse('std::array<unsigned long, 123> unDescribedArray', False)
self.assertEqual(parsed.full_type, 'std::array<unsigned long, 123>')
self.assertEqual(parsed.name, 'unDescribedArray')
self.assertEqual(parsed.array_type, 'unsigned long')
self.assertTrue(parsed.is_builtin_array)
self.assertEqual(parsed.julia_type, r'MVector{123, UInt32}')

parsed = parser.parse('unsigned long longWithReallyStupidName', False)
self.assertEqual(parsed.full_type, 'unsigned long')
self.assertEqual(parsed.name, 'longWithReallyStupidName')
self.assertEqual(parsed.julia_type, r'UInt32')

parsed = parser.parse('NonBuiltIn aType // descriptions are not ignored even though they are not required', False)
self.assertEqual(parsed.full_type, 'NonBuiltIn')
self.assertEqual(parsed.name, 'aType')
self.assertEqual(parsed.description, 'descriptions are not ignored even though they are not required')
self.assertTrue(not parsed.is_builtin)

self.assertEqual(parsed.julia_type, r'NonBuiltIn')

def test_string_representation(self):
"""Test that the string representation that is used in the jinja2 templates
includes the default initialization"""
Expand Down
7 changes: 5 additions & 2 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def __init__(self, yamlfile, install_dir, package_name, io_handlers, verbose, dr
self.any_changes = False

def _process_parent_module(self, datamodel):
"""Process parent module of julia that contains constructor definitions
of components and datatypes"""
self._fill_templates("ParentModule", datamodel)

def process(self):
Expand Down Expand Up @@ -259,7 +261,7 @@ def _process_component(self, name, component):
includes.update(component.get("ExtraCode", {}).get("includes", "").split('\n'))

component['includes'] = self._sort_includes(includes)
component['includes_jl'] = {'struct': includes_jl}
component['includes_jl'] = {'struct': sorted(includes_jl)}
component['class'] = DataType(name)

self._fill_templates('Component', component)
Expand Down Expand Up @@ -289,6 +291,7 @@ def _preprocess_for_julia(self, datatype):
if not member.is_builtin:
includes_jl_struct.add(self._build_julia_include(member))
datatype['includes_jl']['struct'].update((includes_jl_struct))
sorted(datatype['includes_jl']['struct'])

@staticmethod
def _get_julia_params(datatype):
Expand Down Expand Up @@ -431,7 +434,7 @@ def _preprocess_datatype(self, name, definition):
data['class'] = DataType(name)
data['includes_data'] = self._get_member_includes(definition["Members"])
data['includes_jl'] = {'struct': self._get_member_includes(definition["Members"], julia=True)}
data['params_jl'] = self._get_julia_params(data)
data['params_jl'] = sorted(self._get_julia_params(data))
self._preprocess_for_class(data)
self._preprocess_for_obj(data)
self._preprocess_for_collection(data)
Expand Down
2 changes: 0 additions & 2 deletions python/templates/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ set(PODIO_TEMPLATES
${CMAKE_CURRENT_LIST_DIR}/macros/sioblocks.jinja2
${CMAKE_CURRENT_LIST_DIR}/macros/utils.jinja2

${CMAKE_CURRENT_LIST_DIR}/JuliaCollection.jl.jinja2
${CMAKE_CURRENT_LIST_DIR}/Constructor.jl.jinja2
${CMAKE_CURRENT_LIST_DIR}/MutableStruct.jl.jinja2
${CMAKE_CURRENT_LIST_DIR}/ParentModule.jl.jinja2
)

0 comments on commit a589890

Please sign in to comment.