def _buildAndValidateManyCustomers(): icdOdsPath = dev_test.getTestIcdPath("customers.ods") locCsvPath = dev_test.getTestFile("input", "lots_of_customers.csv") dev_test.createLotsOfCustomersCsv(locCsvPath, customerCount=20000) exitCode = _cutplace.main(["test_performance.py", icdOdsPath, locCsvPath]) if exitCode != 0: raise ValueError(u"exit code of performance test must be 0 but is %d" % exitCode)
def testValidCsvs(self): VALID_PREFIX = "valid_" testsInputFolder = dev_test.getTestFolder("input") validCsvFileNames = _tools.listdirMatching(testsInputFolder, VALID_PREFIX + ".*\\.csv", ".*with_head.*") validCsvPaths = list( os.path.join(testsInputFolder, fileName) for fileName in validCsvFileNames) for dataPath in validCsvPaths: # Compute the base name of the related ICD. baseFileName = os.path.basename(dataPath) baseFileNameWithoutCsvSuffix = os.path.splitext(baseFileName)[0] baseFileNameWithoutValidPrefixAndCsvSuffix = baseFileNameWithoutCsvSuffix[ len(VALID_PREFIX):] # Compute the full path of the related ICD. icdBaseName = baseFileNameWithoutValidPrefixAndCsvSuffix.split( "_")[0] icdPath = dev_test.getTestIcdPath(icdBaseName + ".csv") if not os.path.exists(icdPath): icdPath = dev_test.getTestIcdPath(icdBaseName + ".ods") self.assertTrue( os.path.exists(icdPath), u"icd '%s' (or '*.csv') for data file '%s' must be created" % (icdPath, dataPath)) # Now validate the data. exitCode = _cutplace.main(["test_cutplace.py", icdPath, dataPath]) self.assertEqual(exitCode, 0)
def testCanValidateIcdWithPlugins(self): icdPath = dev_test.getTestIcdPath("customers_with_plugins.ods") exitCode = _cutplace.main([ "test_cutplace.py", "--plugins", dev_test.getTestPluginsPath(), icdPath ]) self.assertEqual(exitCode, 0)
def testSplitBrokenData(self): icdPath = dev_test.getTestIcdPath("customers.ods") dataPath = dev_test.getTestInputPath("broken_customers.csv") exitCode = _cutplace.main(["test_cutplace.py", "--split", icdPath, dataPath]) self.assertEquals(exitCode, 1) acceptedDataPath = dev_test.getTestInputPath("broken_customers_accepted.csv") rejectedDataPath = dev_test.getTestInputPath("broken_customers_rejected.txt") self.assertNotEqual(os.path.getsize(acceptedDataPath), 0) self.assertNotEqual(os.path.getsize(rejectedDataPath), 0) os.remove(acceptedDataPath) os.remove(rejectedDataPath)
def testSplitBrokenData(self): icdPath = dev_test.getTestIcdPath("customers.ods") dataPath = dev_test.getTestInputPath("broken_customers.csv") exitCode = _cutplace.main( ["test_cutplace.py", "--split", icdPath, dataPath]) self.assertEquals(exitCode, 1) acceptedDataPath = dev_test.getTestInputPath( "broken_customers_accepted.csv") rejectedDataPath = dev_test.getTestInputPath( "broken_customers_rejected.txt") self.assertNotEqual(os.path.getsize(acceptedDataPath), 0) self.assertNotEqual(os.path.getsize(rejectedDataPath), 0) os.remove(acceptedDataPath) os.remove(rejectedDataPath)
def testValidCsvs(self): VALID_PREFIX = "valid_" testsInputFolder = dev_test.getTestFolder("input") validCsvFileNames = _tools.listdirMatching(testsInputFolder, VALID_PREFIX + ".*\\.csv", ".*with_head.*") validCsvPaths = list(os.path.join(testsInputFolder, fileName) for fileName in validCsvFileNames) for dataPath in validCsvPaths: # Compute the base name of the related ICD. baseFileName = os.path.basename(dataPath) baseFileNameWithoutCsvSuffix = os.path.splitext(baseFileName)[0] baseFileNameWithoutValidPrefixAndCsvSuffix = baseFileNameWithoutCsvSuffix[len(VALID_PREFIX):] # Compute the full path of the related ICD. icdBaseName = baseFileNameWithoutValidPrefixAndCsvSuffix.split("_")[0] icdPath = dev_test.getTestIcdPath(icdBaseName + ".csv") if not os.path.exists(icdPath): icdPath = dev_test.getTestIcdPath(icdBaseName + ".ods") self.assertTrue(os.path.exists(icdPath), u"icd '%s' (or '*.csv') for data file '%s' must be created" % (icdPath, dataPath)) # Now validate the data. exitCode = _cutplace.main(["test_cutplace.py", icdPath, dataPath]) self.assertEqual(exitCode, 0)
def testListEncodings(self): exitCode = _cutplace.main(["test_cutplace.py", "--list-encodings"]) self.assertEqual(exitCode, 0)
def testCanValidateDataWithPlugins(self): icdPath = dev_test.getTestIcdPath("customers_with_plugins.ods") dataPath = dev_test.getTestInputPath("valid_customers.csv") exitCode = _cutplace.main(["test_cutplace.py", "--plugins", dev_test.getTestPluginsPath(), icdPath, dataPath]) self.assertEqual(exitCode, 0)
def testValidNativeExcelFormats(self): icdPath = dev_test.getTestIcdPath("native_excel_formats.ods") dataPath = dev_test.getTestInputPath("valid_native_excel_formats.xls") exitCode = _cutplace.main(["test_cutplace.py", icdPath, dataPath]) self.assertEqual(exitCode, 0)
def testValidFixedTxt(self): icdPath = dev_test.getTestIcdPath("customers_fixed.ods") dataPath = dev_test.getTestInputPath("valid_customers_fixed.txt") exitCode = _cutplace.main(["test_cutplace.py", icdPath, dataPath]) self.assertEqual(exitCode, 0)