1#!/usr/bin/python 2 3import unittest as u 4import re, fnmatch, os, sys 5 6sampleMappingFile = '../examples/samples.mapping.txt' 7cSamplesDir = '../examples/' 8javaSamplesDir = '../examples/java/' 9cppSamplesDir = '../examples/c++/' 10 11class SampleNames(u.TestCase): 12 13 def test_existing_samples(self): 14 missing_c_files = [] 15 missing_cpp_files = [] 16 missing_java_files = [] 17 18 with open (sampleMappingFile, "r") as f: 19 for line in f: 20 sampleNames = line.split(); 21 22 cSampleName = sampleNames[0] 23 javaSampleName = sampleNames[1] 24 25 #check for C files 26 if cSampleName.endswith('.c'): 27 ok = False 28 for file in os.listdir(cSamplesDir): 29 if file == cSampleName: 30 ok = True 31 break 32 if not ok: 33 missing_c_files.append(cSampleName) 34 35 #check for Cpp files 36 if cSampleName.endswith('.cpp'): 37 ok = False 38 for file in os.listdir(cppSamplesDir): 39 if file == cSampleName: 40 ok = True 41 break 42 if not ok: 43 missing_cpp_files.append(cSampleName) 44 45 #check for java files 46 javaSampleName = javaSampleName.lstrip("java/") 47 if javaSampleName.endswith('.java'): 48 ok = False 49 for file in os.listdir(javaSamplesDir): 50 if file == javaSampleName: 51 ok = True 52 break 53 if not ok: 54 missing_java_files.append(javaSampleName) 55 56 self.assertEqual( len(missing_java_files) + len(missing_c_files) + len(missing_cpp_files), 0, 57 "\nThe following files are missing from samples:\n" + \ 58 "\n".join(missing_c_files) + "\n" + \ 59 "\n".join(missing_cpp_files) + "\n" + \ 60 "\n".join(missing_java_files)) 61 62if __name__ == '__main__': 63 u.main() 64 65