Beispiel #1
0
    def test_validate_data_main_api_connect_error(self, name, file_path,
                                                  prediction_type,
                                                  target_column, categories,
                                                  ordinals):
        result = io.StringIO()
        testargs = [
            "program.py", file_path, '-target', target_column,
            '-identifier_type', 'fileid'
        ]

        if (categories):
            testargs.extend(
                ['-categorical_features',
                 simplejson.dumps(categories)])
        if (ordinals):
            testargs.extend(['-ordinal_features', simplejson.dumps(ordinals)])
        if (prediction_type):
            testargs.extend(['-prediction_type', prediction_type])

        with patch.object(sys, 'argv', testargs):
            sys.stdout = result
            validateDataset.main()
            sys.stdout = sys.__stdout__
        logger.debug("testargs: " + str(testargs) + " res: " +
                     result.getvalue())
        self.assertTrue(result.getvalue())
        objResult = simplejson.loads(result.getvalue())

        self.assertIsInstance(objResult, dict)
        self.assertEqual(list(objResult), ["success", "errorMessage"])
        self.assertEqual(objResult['success'], False)
        #self.assertRegex(objResult['errorMessage'], "^Exception: ConnectionError\(MaxRetryError")
        #self.assertRegex(objResult['errorMessage'], "^Exception: ConnectTimeout\(MaxRetryError")
        self.assertRegex(objResult['errorMessage'],
                         "^Exception: Connect.*\(MaxRetryError")
Beispiel #2
0
    def test_validate_data_main_file_bad(self, name, file_path,
                                         prediction_type, target_column,
                                         categories, ordinals,
                                         expectedMessage):
        result = io.StringIO()
        testargs = [
            "program.py", file_path, '-target', target_column,
            '-identifier_type', 'filepath'
        ]

        if (categories):
            testargs.extend(
                ['-categorical_features',
                 simplejson.dumps(categories)])
        if (ordinals):
            testargs.extend(['-ordinal_features', simplejson.dumps(ordinals)])
        if (prediction_type):
            testargs.extend(['-prediction_type', prediction_type])

        with patch.object(sys, 'argv', testargs):
            sys.stdout = result
            validateDataset.main()
            sys.stdout = sys.__stdout__
        logger.debug("testargs: " + str(testargs) + " res: " +
                     result.getvalue())
        self.assertTrue(result.getvalue())
        objResult = simplejson.loads(result.getvalue())
        self.assertEqual(objResult, {
            "success": False,
            "errorMessage": expectedMessage
        })