Esempio n. 1
0
                        'propValue':
                        'Veterans Health Administration National Drug File'
                    }]
                }
            }
        }]

    def tearDown(self):
        pass

    def test_fetch_properties_by_rxcui(self):
        for test_case in self.TEST_CASES:
            rxcui = test_case['rxcui']
            expected_properties = test_case['properties']
            actual_properties = self.client.fetch_properties_by_rxcui(rxcui)

            self.assertEqual(expected_properties, actual_properties)

    def test_fetch_name_by_rxcui(self):
        for test_case in self.TEST_CASES:
            rxcui = test_case['rxcui']
            expected_name = test_case['name']
            actual_name = self.client.fetch_name_by_rxcui(rxcui)

            self.assertEqual(expected_name, actual_name)


if __name__ == '__main__':
    suite = make_test_suite(TestRxNormClient)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
Esempio n. 2
0
        self.assertEqualFile(test_file, verify_file)

    def test_upload_file(self):
        # Define file to be uploaded.
        local_file_path = '/'.join([self.package, self.upload_file_name])
        # Upload file.
        remote_file = self.client.upload_file(local_file_path,
                                              self.remote_folder_id,
                                              self.upload_file_name)
        # Check file content.
        remote_content = remote_file.content()
        local_content = open('/'.join([self.package,
                                       self.upload_file_name])).read()

        self.assertEqual(remote_content, local_content)

    def test_download_folder(self):
        # Define file to be downloaded.
        verify_local_dir_path = '/'.join([self.package, 'box-test-verify'])
        test_local_dir_path = '/'.join([self.package, 'box-test'])
        self.client.download_folder(self.remote_folder_id, test_local_dir_path)
        # Check folder content.
        # TODO(sbala): Write a proper validation of this check, which was only
        # checked ad-hoc on the test case.
        # filecmp.dircmp(test_local_dir_path, verify_local_dir_path).report_full_closure()


if __name__ == "__main__":
    suite = make_test_suite(TestBoxClient)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
Esempio n. 3
0
            metric=RegressorAnalyzer.EXPLAINED_VARIANCE_SCORE)

        self.assertEqual(expected_explained_variance,
                         actual_explained_variance)

    def test_build_report(self):
        # Build report.
        expected_report = RANDOM_REGRESSION_TEST_CASE['report']
        actual_report = self._analyzer.build_report()

        # Assert values are correct.
        assert_frame_equal(expected_report, actual_report)

        # Build paths for expected and actual report.
        test_dir = os.path.dirname(os.path.abspath(__file__))
        expected_report_name = 'expected-linear-predictor.report'
        actual_report_name = 'actual-linear-predictor.report'
        expected_report_path = '/'.join([test_dir, expected_report_name])
        actual_report_path = '/'.join([test_dir, actual_report_name])

        # Write the report.
        self._analyzer.write_report(actual_report_path)

        # Assert files equal.
        self.assertTrue(filecmp.cmp(expected_report_path, actual_report_path))


if __name__ == '__main__':
    suite = make_test_suite(TestRegressorAnalyzer)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
Esempio n. 4
0
    def test_build_report(self):
        # Build report.
        expected_report = RANDOM_100_TEST_CASE['report']
        actual_report = self._ml_analyzer.build_report()[0]
        log.debug('expected_report: %s' % expected_report)
        log.debug('actual_report: %s' % actual_report)
        assert_frame_equal(expected_report, actual_report)

        # Build bootstrapped report.
        expected_report = RANDOM_100_TEST_CASE['ci']['report']
        actual_report = self._ml_analyzer.build_report(ci=0.95)[0]
        assert_frame_equal(expected_report, actual_report)

        # Build paths for expected and actual report.
        test_dir = os.path.dirname(os.path.abspath(__file__))
        actual_report_name = 'actual-list-classifier.report'
        actual_report_path = '/'.join([test_dir, actual_report_name])

        # Write the report.
        self._ml_analyzer.write_report(actual_report_path)

        # Not sure how to validate this at the moment, so just validate
        # that it actually passes.
        self.assertTrue(True)


if __name__ == '__main__':
    suite = make_test_suite(TestClassifierAnalyzer)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
Esempio n. 5
0
        # Assert values are correct.
        self.assertEqual(expected_accuracy, actual_accuracy)
        self.assertEqual(expected_lower_ci, lower_ci)
        self.assertEqual(expected_upper_ci, upper_ci)

    def test_build_report(self):
        # Build report.
        expected_report = MANUAL_PREDICTION_TEST_CASE['report']
        actual_report = self._analyzer.build_report()

        # Assert values are correct.
        assert_frame_equal(expected_report, actual_report)

        # Build paths for expected and actual report.
        test_dir = os.path.dirname(os.path.abspath(__file__))
        expected_report_name = 'expected-list-predictor.report'
        actual_report_name = 'actual-list-predictor.report'
        expected_report_path = '/'.join([test_dir, expected_report_name])
        actual_report_path = '/'.join([test_dir, actual_report_name])

        # Write the report.

        self._analyzer.write_report(actual_report, actual_report_path)

        # Assert files equal.
        self.assertTrue(filecmp.cmp(expected_report_path, actual_report_path))

if __name__=='__main__':
    suite = make_test_suite(TestPredictorAnalyzer)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
Esempio n. 6
0
        fs.set_input_matrix(X, y)

        # Select k best features.
        fs.select(k=k, percentile=percentile)
        feature_ranks = fs.compute_ranks()

        return feature_ranks

    def _validate_feature_ranks(self, coefs, sorted_coefs, feature_ranks, k, strict=True):
        # Identify the minimum true coefficient value for which we expect
        # feature must have been selected.
        min_true_coef_val = sorted_coefs[k]

        if strict:
            # Iterate through features to confirm we selected at least the k
            # we know we should have selected.
            for feature_index in range(len(feature_ranks)):
                if coefs[feature_index] > min_true_coef_val:
                    # The ordering of the significant features isn't maintained
                    # by FeatureSelector. Therefore, just confirm that the k
                    # features with the highest true weights are selected.
                    self.assertTrue(feature_ranks[feature_index] <= k)
        else:
            # Just confirm the top two were selected.
            self.assertTrue(feature_ranks[1] <= k)
            self.assertTrue(feature_ranks[7] <= k)

if __name__=="__main__":
    suite = make_test_suite(TestFeatureSelector)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
        actual_hyperparams = self._bsc.hyperparams()
        self._assert_equal_hyperparams(expected_hyperparams['model_true'],
                                       actual_hyperparams['model_true'])
        self._assert_equal_hyperparams(expected_hyperparams['model_false'],
                                       actual_hyperparams['model_false'])

        # Test params.
        expected_params = expected_params_by_algorithm[algorithm]
        actual_params = self._bsc.params()
        self.assertEqual(expected_params, actual_params)

        # Test str.
        expected_str = expected_str_by_algorithm[algorithm]
        actual_str = str(self._bsc)
        self.assertEqual(expected_str, actual_str)

        # Test description.
        expected_description = expected_descriptions_by_algorithm[algorithm]
        actual_description = self._bsc.description()
        self.assertEqual(expected_description, actual_description)

        # Test predictions.
        expected_y_pred = expected_y_pred_by_algorithm[algorithm]
        actual_y_pred = self._bsc.predict(X_test)
        self.assertEqualList(expected_y_pred, actual_y_pred)


if __name__ == '__main__':
    suite = make_test_suite(TestBifurcatedSupervisedClassifier)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
        # Verify feature addition.
        expected_matrix = MANUAL_FM_TEST_CASE['test_zero_data_imputation']
        actual_matrix = self.fmt.fetch_matrix()
        assert_frame_equal(expected_matrix, actual_matrix)

    def test_median_data_imputation(self):
        # Impute median(f2).
        self.fmt.impute(feature="f2", strategy=FeatureMatrixTransform.IMPUTE_STRATEGY_MEDIAN)

        # Verify feature addition.
        expected_matrix = MANUAL_FM_TEST_CASE['test_median_data_imputation']
        actual_matrix = self.fmt.fetch_matrix()
        assert_frame_equal(expected_matrix, actual_matrix)

    def _power_law_dist(self):
        return powerlaw.rvs(1.66, random_state=2)

    def test_distrbution_data_imputation(self):
        # Impute distribution(f2).
        self.fmt.impute(feature="f2", distribution=self._power_law_dist, \
            strategy=FeatureMatrixTransform.IMPUTE_STRATEGY_DISTRIBUTION)

        # Verify feature addition.
        expected_matrix = MANUAL_FM_TEST_CASE['test_distribution_data_imputation']
        actual_matrix = self.fmt.fetch_matrix()
        assert_frame_equal(expected_matrix, actual_matrix)

if __name__=="__main__":
    suite = make_test_suite(TestFeatureMatrixTransform)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)
Esempio n. 9
0
        fm_io = FeatureMatrixIO()

        # Build paths for test files.
        app_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
        no_header_file_name = 'test-matrix-no-header.tab'
        with_header_file_name = 'test-matrix-with-header.tab'
        no_header_file_path = os.path.join(app_dir, no_header_file_name)
        with_header_file_path = os.path.join(app_dir, with_header_file_name)

        # Read data frames from test files.
        matrix_no_header = MANUAL_TEST_CASE['matrix_no_header']
        matrix_header = MANUAL_TEST_CASE['custom_header']

        # Write data frame without header.
        no_header_temp_file_name = 'no-header-temp-file.tab'
        self._no_header_temp_file_path = os.path.join(app_dir, no_header_temp_file_name)
        fm_io.write_data_frame_to_file(matrix_no_header, self._no_header_temp_file_path)

        # Write data frame with header.
        with_header_temp_file_name = 'header-temp-file.tab'
        self._with_header_temp_file_path = os.path.join(app_dir, with_header_temp_file_name)
        fm_io.write_data_frame_to_file(matrix_no_header, self._with_header_temp_file_path, matrix_header)

        # Validate output files.
        self.assertTrue(filecmp.cmp(no_header_file_path, self._no_header_temp_file_path))
        self.assertTrue(filecmp.cmp(with_header_file_path, self._with_header_temp_file_path))

if __name__=="__main__":
    suite = make_test_suite(TestFeatureMatrixIO)
    unittest.TextTestRunner(verbosity=TEST_RUNNER_VERBOSITY).run(suite)