def test_create_dir(self): path = self.get_random_path() create_dir(path) assert_true(os.path.exists(path)) # should not raise OSError if directory already exists create_dir(path) assert_true(os.path.exists(path))
def test_exception_class_hierarchy(self): """Test that the C++-defined Python exception type objects have the right class hiearchy.""" # Base class inherits from Exception T.assert_true(issubclass(C_GP.OptimalLearningException, Exception)) type_objects = (C_GP.BoundsException, C_GP.InvalidValueException, C_GP.SingularMatrixException) for type_object in type_objects: T.assert_true(issubclass(type_object, C_GP.OptimalLearningException))
def test_move_file(self): src = self.get_random_file() dst = self.get_random_path() assert_true(os.path.exists(src)) assert_false(os.path.exists(dst)) move_file(src, dst) assert_false(os.path.exists(src)) assert_true(os.path.exists(dst))
def test_msg_servlet_for_watchers(self, _): resp = self.fetch("/msg", method="POST", body="state=added&message=foo&id=1") T.assert_is(resp.error, None) call_arguments = self.call_mock.call_args[0][0] T.assert_true("/nail/sys/bin/nodebot" in call_arguments[0]) T.assert_true("-i" in call_arguments[1]) T.assert_true("testuser" in call_arguments[4]) T.assert_true("testwatcher_1" in call_arguments[4]) T.assert_true("foo" in call_arguments[4])
def test_msg_servlet_for_watchers(self, _): resp = self.fetch('/msg', method='POST', body='state=added&message=foo&id=1') T.assert_is(resp.error, None) call_arguments = self.call_mock.call_args[0][0] T.assert_true('/nail/sys/bin/nodebot' in call_arguments[0]) T.assert_true('-i' in call_arguments[1]) T.assert_true('testuser' in call_arguments[4]) T.assert_true('testwatcher_1' in call_arguments[4]) T.assert_true('foo' in call_arguments[4])
def test_exception_class_hierarchy(self): """Test that the C++-defined Python exception type objects have the right class hiearchy.""" # Base class inherits from Exception T.assert_true(issubclass(C_GP.OptimalLearningException, Exception)) type_objects = (C_GP.BoundsException, C_GP.InvalidValueException, C_GP.SingularMatrixException) for type_object in type_objects: T.assert_true( issubclass(type_object, C_GP.OptimalLearningException))
def test_multistart_qei_expected_improvement_dfo(self): """Check that multistart optimization (BFGS) can find the optimum point to sample (using 2-EI).""" numpy.random.seed(7860) index = numpy.argmax(numpy.greater_equal(self.num_sampled_list, 20)) domain, gaussian_process = self.gp_test_environments[index] tolerance = 6.0e-5 num_multistarts = 3 # Expand the domain so that we are definitely not doing constrained optimization expanded_domain = TensorProductDomain([ClosedInterval(-4.0, 3.0)] * self.dim) num_to_sample = 2 repeated_domain = RepeatedDomain(num_to_sample, expanded_domain) num_mc_iterations = 100000 # Just any random point that won't be optimal points_to_sample = repeated_domain.generate_random_point_in_domain() ei_eval = ExpectedImprovement(gaussian_process, points_to_sample, num_mc_iterations=num_mc_iterations) # Compute EI and its gradient for the sake of comparison ei_initial = ei_eval.compute_expected_improvement() ei_optimizer = LBFGSBOptimizer(repeated_domain, ei_eval, self.BFGS_parameters) best_point = multistart_expected_improvement_optimization(ei_optimizer, num_multistarts, num_to_sample) # Check that gradients are "small" or on border. MC is very inaccurate near 0, so use finite difference # gradient instead. ei_eval.current_point = best_point ei_final = ei_eval.compute_expected_improvement() finite_diff_grad = numpy.zeros(best_point.shape) h_value = 0.00001 for i in range(best_point.shape[0]): for j in range(best_point.shape[1]): best_point[i, j] += h_value ei_eval.current_point = best_point ei_upper = ei_eval.compute_expected_improvement() best_point[i, j] -= 2 * h_value ei_eval.current_point = best_point ei_lower = ei_eval.compute_expected_improvement() best_point[i, j] += h_value finite_diff_grad[i, j] = (ei_upper - ei_lower) / (2 * h_value) self.assert_vector_within_relative(finite_diff_grad, numpy.zeros(finite_diff_grad.shape), tolerance) # Check that output is in the domain T.assert_true(repeated_domain.check_point_inside(best_point)) # Since we didn't really converge to the optimal EI (too costly), do some other sanity checks # EI should have improved T.assert_gt(ei_final, ei_initial)
def test_normalize_buffer_to_unicode(self): b = buffer("this is buffer") val = osxcollector._normalize_val(b) T.assert_true(isinstance(val, unicode))
def test_normalize_unicode(self): u = '\u20AC' val = osxcollector._normalize_val(u) T.assert_true(isinstance(val, unicode))
def test_assert_true(self): assert_true(1) assert_true('False') assert_true([0]) assert_true(['']) assert_true({'a': 0})
def test_has_uppercase(self): assert_true(has_uppercase('Foo')) assert_true(has_uppercase('foO')) assert_false(has_uppercase('foo')) assert_false(has_uppercase(''))
def test(self): content, content_type = self.form.get_value() lines = content.split('\n') assert_true(lines[0].startswith('--')) assert_true(content_type.startswith("multipart/form-data"))
def test_in_bash(self): os.environ['SHELL'] = '/bin/bash' assert_true(in_bash()) os.environ['SHELL'] = '/usr/bin/zsh' assert_false(in_bash())
def test(self): url = self.request.url assert_equal(url, "http://localhost:8888") body = self.request.body assert_true(body is None)