~chris-rogers/maus/emr_mc_digitization

« back to all changes in this revision

Viewing changes to tests/style/_test_datastructure.py

  • Committer: Chris Rogers
  • Date: 2014-04-16 11:48:45 UTC
  • mfrom: (707 merge)
  • mto: This revision was merged to the branch mainline in revision 711.
  • Revision ID: chris.rogers@stfc.ac.uk-20140416114845-h3u3q7pdcxkxvovs
Update to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Datastructure items should all the MAUS_VERSIONED_CLASS_DEF macro
 
3
"""
 
4
 
 
5
import unittest
 
6
import subprocess
 
7
import os
 
8
 
 
9
def is_header(a_path):
 
10
    """
 
11
    Return true if it is a header file
 
12
    """
 
13
    return a_path[-3:] == ".hh" and a_path[-6:] != "inl.hh"
 
14
 
 
15
EXCLUSIONS = [
 
16
"src/common_cpp/DataStructure/LinkDef.hh",
 
17
"src/common_cpp/DataStructure/Global/ReconEnums.hh",
 
18
]
 
19
 
 
20
def is_ignored(a_path):
 
21
    """
 
22
    Return true if file is in the exclusion list
 
23
    """
 
24
    strip_path = a_path[len(os.environ["MAUS_ROOT_DIR"])+1:]
 
25
    return strip_path in EXCLUSIONS
 
26
 
 
27
class TestDataStructure(unittest.TestCase): # pylint: disable=R0904
 
28
    """
 
29
    Check data structure vs ROOT integrity
 
30
    """
 
31
    def test_data_structure(self):
 
32
        """
 
33
        @brief walk the directory structure from target_dir
 
34
        """
 
35
        target_dir = "${MAUS_ROOT_DIR}/src/common_cpp/DataStructure"
 
36
        target_dir = os.path.expandvars(target_dir)
 
37
        for this_dir, subdirs, files in os.walk(target_dir):
 
38
            print 'In', this_dir, 'with', len(subdirs), 'subdirectories'
 
39
            for file_name in files:
 
40
                path = os.path.join(this_dir, file_name)
 
41
                if is_header(path) and not is_ignored(path):
 
42
                    print '   ', path
 
43
                    out = subprocess.check_output(['grep',
 
44
                                                   'MAUS_VERSIONED_CLASS_DEF',
 
45
                                                    path])
 
46
                    self.assertNotEqual(out, '')
 
47
 
 
48
if __name__ == "__main__":
 
49
    unittest.main()
 
50