Beispiel #1
0
 def test_clean_up_folder(self):
     with dcs.capture_output():
         dcs.setup_dir(self.folder)
         dcs.write_text_file(self.filename, self.text)
     with dcs.capture_output() as (out, err):
         dcs.setup_dir(self.folder)
     output = out.getvalue().strip()
     self.assertEqual(output, 'Files/Sub-folders were removed from: "{}"'.format(self.folder))
Beispiel #2
0
 def test_clean_up_recursively(self):
     with dcs.capture_output():
         dcs.setup_dir(self.subdir)
         dcs.write_text_file(self.subfile, self.text)
     with dcs.capture_output() as (out, err):
         dcs.setup_dir(self.folder, rec=True)
     output = out.getvalue().strip()
     self.assertEqual(output, 'Files/Sub-folders were removed from: "{}"\n'.format(self.subdir) + \
         'Files/Sub-folders were removed from: "{}"'.format(self.folder))
Beispiel #3
0
 def test_clean_up_partial(self):
     with dcs.capture_output():
         dcs.setup_dir(self.folder)
         dcs.write_text_file(self.filename, '')
         dcs.setup_dir(self.subdir)
         dcs.write_text_file(self.subfile, '')
     with dcs.capture_output() as out:
         dcs.setup_dir(self.folder, rec=False)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, 'Files/Sub-folders were removed from: "{}"'.format(self.folder))
Beispiel #4
0
 def tearDownClass(cls):
     if os.path.isdir(cls.extra):
         os.rmdir(cls.extra)
     if os.path.isdir(cls.output):
         with capture_output():
             setup_dir(cls.output)
         os.rmdir(cls.output)
     if os.path.isdir(cls.folder):
         with capture_output():
             setup_dir(cls.folder)
         os.rmdir(cls.folder)
Beispiel #5
0
 def test_bad_comparison(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_classes(self.c1, self.c2)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, 'b is different from c1 to c2.\nc is only in c1.\nd is only in c2.\n"c1" and "c2" are not the same.')
     self.assertFalse(is_same)
Beispiel #6
0
 def test_no_logging(self):
     self.logger.set_level(0)
     with dcs.capture_output() as out:
         self.figs = dcs.plot_bpe_results(self.bpe_results, plots=self.plots)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '')
Beispiel #7
0
 def test_no_logging(self):
     with dcs.capture_output() as out:
         is_valid = dcs.validate_opti_opts(self.opti_opts)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(is_valid)
     self.assertEqual(output,'')
Beispiel #8
0
 def test_nothing_missing(self):
     with capture_output() as out:
         dip.find_missing_nums(self.folder_exclusions[0])
     output = out.getvalue().strip()
     out.close()
     lines = output.split('\n')
     self.assertTrue(lines[0].startswith('No number found: "'))
Beispiel #9
0
 def test_printing_instance_repr(self):
     with dcs.capture_output() as out:
         print(repr(_Example_Enum.field_one))
         print(repr(_Example_Enum.field_two))
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '<_Example_Enum.field_one: 1>\n<_Example_Enum.field_two: 2>')
Beispiel #10
0
 def test_printing_instance_str(self):
     with dcs.capture_output() as out:
         print(_Example_Enum.field_one)
         print(_Example_Enum.field_two)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '_Example_Enum.field_one: 1\n_Example_Enum.field_two: 2')
Beispiel #11
0
 def test_convergence3(self):
     with dcs.capture_output() as out:
         convergence = dcs.bpe._check_for_convergence(self.opti_opts, self.cosmax, self.delta_step_len, -2.5)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(convergence)
     self.assertEqual(output, 'Declare convergence because abs(pred_func_change) of 2.5 <= options.tol_delta_cost of 3')
Beispiel #12
0
 def test_nominal(self):
     with dcs.capture_output() as out:
         print(self.x)
     lines = out.getvalue().strip().split('\n')
     out.close()
     # normalize whitespace
     lines = self._norm_output(lines)
     self.assertEqual(lines, self.x_print)
     with dcs.capture_output() as out:
         with dcs.full_print():
             print(self.x)
     lines = out.getvalue().strip().split('\n')
     # normalize whitespace
     lines = self._norm_output(lines)
     out.close()
     self.assertEqual(lines, self.x_full)
Beispiel #13
0
 def test_std_out(self):
     with dcs.capture_output() as (out, err):
         print('Hello, World!')
     output = out.getvalue().strip()
     error  = err.getvalue().strip()
     self.assertEqual(output, 'Hello, World!')
     self.assertEqual(error, '')
Beispiel #14
0
 def test_nominal(self):
     with capture_output() as out:
         ratio = fiver._display_progress(self.ix, self.nums)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, 'Progess: 56.2%')
     self.assertEqual(ratio, self.ratio)
Beispiel #15
0
 def test_str(self):
     with dcs.capture_output() as out:
         print(self.bpe_results)
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertEqual(lines[0], 'BpeResults:')
     self.assertTrue(lines[1].startswith('  begin_params: '))
Beispiel #16
0
 def test_noreplace(self):
     with capture_output() as out:
         dip.convert_tif_to_jpg(self.folder,
                                self.size3,
                                self.size3,
                                replace=False)
     output = out.getvalue().strip()
     out.close()
     lines = output.split('\n')
     self.assertTrue(output.startswith('Processing folder: "'))
     self.assertTrue(output.endswith('Batch processing complete.'))
     for this_line in lines:
         if this_line.startswith(
                 ' Skipping due to pre-existing jpg file: "'):
             break
     else:
         self.assertTrue(
             False, 'No images were skipped due to pre-existing ones.')
     for this_line in lines:
         if this_line.startswith(' Skipping file   : "{}"'.format(
                 self.name6)):
             break
     else:
         self.assertTrue(False,
                         'File "{}" was not skipped.'.format(self.name6))
Beispiel #17
0
 def test_no_name(self):
     with dcs.capture_output() as out:
         dcs.pprint_dict(self.dct)
     lines = out.getvalue().strip().split('\n')
     self.assertEqual(lines[0], 'a   = 1')
     self.assertEqual(lines[1], ' bb  = 2')
     self.assertEqual(lines[2], ' ccc = 3')
Beispiel #18
0
 def test_suppression(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_dicts(self.d1, self.d2, suppress_output=True, names=self.names)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '')
     self.assertFalse(is_same)
Beispiel #19
0
 def test_list_all(self):
     with dcs.capture_output() as out:
         dcs.find_tabs(self.folder, list_all=True)
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertTrue(self.bad1 in lines)
     self.assertFalse(self.bad2 in lines)
Beispiel #20
0
 def test_nominal(self):
     with dcs.capture_output() as out:
         dcs.rename_module(self.folder, self.old_name, self.new_name, self.print_status)
     output = out.getvalue().strip()
     out.close()
     lines = output.split('\n')
     # check for dir creation, files copied, files skipped, files edited
     # expect at least one of each
     for this_line in lines:
         if this_line.startswith('Created directory: "'):
             break
     else:
         self.assertTrue(False, 'No directory was created')
     for this_line in lines:
         if this_line.startswith('Copying : '):
             break
     else:
         self.assertTrue(False,'No files were copied.')
     for this_line in lines:
         if this_line.startswith('Editing : '):
             break
     else:
         self.assertTrue(False,'No files were edited.')
     for this_line in lines:
         if this_line.startswith('Skipping: '):
             break
     else:
         self.assertTrue(False,'No files were skipped.')
     self.assertTrue(os.path.isfile(os.path.join(self.new_dir, '__init__.py')))
     self.assertFalse(os.path.isfile(os.path.join(self.new_dir, '__init__.pyc')))
     self.assertTrue(os.path.isfile(os.path.join(self.new_dir, '__init__.misc')))
Beispiel #21
0
 def test_different_extensions(self):
     with dcs.capture_output() as out:
         dcs.find_tabs(self.folder, extensions='txt')
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertEqual(lines[0], '')
     self.assertEqual(len(lines), 1)
Beispiel #22
0
 def test_convergence1(self):
     with dcs.capture_output() as out:
         convergence = dcs.bpe._check_for_convergence(self.opti_opts, 0.5, self.delta_step_len, self.pred_func_change)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(convergence)
     self.assertEqual(output, 'Declare convergence because cosmax of 0.5 <= options.tol_cosmax_grad of 1')
Beispiel #23
0
 def test_bad_comparison(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_dicts(self.d1, self.d2)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, 'b is different.\nc is only in d1.\nd is only in d2.\n"d1" and "d2" are not the same.')
     self.assertFalse(is_same)
Beispiel #24
0
 def test_small1(self):
     with dcs.capture_output() as out:
         with dcs.full_print():
             print(np.array(0))
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '0')
Beispiel #25
0
 def test_subclasses_match(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_classes(self.c3, self.c3, ignore_callables=False)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '"c1" and "c2" are the same.')
     self.assertTrue(is_same)
Beispiel #26
0
 def test_good_comparison(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_dicts(self.d1, self.d1)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '"d1" and "d2" are the same.')
     self.assertTrue(is_same)
Beispiel #27
0
 def test_no_logging(self):
     self.logger.set_level(0)
     with dcs.capture_output() as out:
         dcs.run_bpe(self.opti_opts)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '')
Beispiel #28
0
 def test_good_comparison(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_classes(self.c1, copy.deepcopy(self.c1))
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '"c1" and "c2" are the same.')
     self.assertTrue(is_same)
Beispiel #29
0
 def test_names(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_dicts(self.d2, self.d2, names=self.names)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '"Dict 1" and "Dict 2" are the same.')
     self.assertTrue(is_same)
Beispiel #30
0
 def test_std_err(self):
     with dcs.capture_output() as (out, err):
         print('Error Raised.', file=sys.stderr)
     output = out.getvalue().strip()
     error  = err.getvalue().strip()
     self.assertEqual(output, '')
     self.assertEqual(error, 'Error Raised.')
Beispiel #31
0
 def test_small2(self):
     with dcs.capture_output() as out:
         with dcs.full_print():
             print(np.array([1.35, 1.58]))
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '[ 1.35  1.58]')
Beispiel #32
0
 def test_no_current(self):
     self.board[self.x, self.y] = knight.Piece.start
     with self.assertRaises(AssertionError):
         with capture_output() as out:
             knight._get_current_position(self.board)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '. . S . .\n. . . . .')
Beispiel #33
0
 def test_bad_sequence(self):
     with capture_output() as out:
         is_valid = knight.check_valid_sequence(self.board, [-2, -2],
                                                print_status=True)
     output = out.getvalue().strip()
     out.close()
     self.assertFalse(is_valid)
     self.assertEqual(output, 'Sequence is not valid.')
Beispiel #34
0
 def test_nominal(self):
     with dcs.capture_output() as out:
         dcs.find_tabs(self.folder, extensions='m', list_all=False, trailing=False)
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertTrue(lines[0].startswith('Evaluating: "'))
     self.assertEqual(lines[1],self.bad1)
     self.assertEqual(len(lines), 2)
Beispiel #35
0
 def test_repeated_sequence2(self):
     with capture_output() as out:
         is_valid = knight.check_valid_sequence(self.board, [2, 4, 2, 2],
                                                print_status=True)
     output = out.getvalue().strip()
     out.close()
     self.assertFalse(is_valid)
     self.assertEqual(output, 'No repeats allowed.\nSequence is not valid.')
Beispiel #36
0
 def test_invalid_sequence(self):
     self.moves = [-2, -2]
     with capture_output() as out:
         with self.assertRaises(ValueError):
             knight.print_sequence(self.board, self.moves)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, self.output[:len(output)])
Beispiel #37
0
 def test_extra2(self):
     with dcs.capture_output() as out:
         qout = dcs.quat_interp(self.time, self.quat, self.ti_extra, inclusive=False)
     output = out.getvalue().strip()
     out.close()
     np.testing.assert_array_almost_equal(qout[:, 1:-1], self.qout)
     np.testing.assert_array_equal(qout[:,[0, -1]], np.nan)
     self.assertEqual(output, 'Desired time not found within input time vector.')
Beispiel #38
0
 def test_no_align(self):
     with dcs.capture_output() as out:
         dcs.pprint_dict(self.dct, name=self.name, align=False)
     lines = out.getvalue().strip().split('\n')
     self.assertEqual(lines[0], 'Example')
     self.assertEqual(lines[1], ' a = 1')
     self.assertEqual(lines[2], ' bb = 2')
     self.assertEqual(lines[3], ' ccc = 3')
Beispiel #39
0
 def test_no_final_position(self):
     self.board[0, 4] = knight.Piece.null
     with capture_output() as out:
         with self.assertRaises(ValueError):
             knight.solve_min_puzzle(self.board)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, 'Initializing solver.')
Beispiel #40
0
 def test_other_costs(self):
     self.board = np.where(self.board == knight.Piece.null,
                           knight.Piece.water, self.board)
     with capture_output() as out:
         knight.print_sequence(self.board, self.moves)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, self.output2)
Beispiel #41
0
 def test_subclasses_norecurse(self):
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_classes(self.c3, self.c4, ignore_callables=False, compare_recursively=False)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, 'b is different from c1 to c2.\n' + \
         'c is only in c1.\nd is only in c2.\n"c1" and "c2" are not the same.')
     self.assertFalse(is_same)
Beispiel #42
0
 def test_nominal(self):
     with dcs.capture_output() as out:
         (bpe_results, results) = dcs.run_bpe(self.opti_opts)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(output.startswith('******************************\nValidating optimization options.'))
     self.assertTrue(isinstance(bpe_results, dcs.BpeResults))
     self.assertTrue(isinstance(results, np.ndarray))
Beispiel #43
0
 def test_multiple_currents(self):
     self.board[self.x + 1, self.y + 1] = knight.Piece.current
     with self.assertRaises(AssertionError):
         with capture_output() as out:
             knight._get_current_position(self.board)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '. . K . .\n. . . K .')
Beispiel #44
0
 def test_nominal(self):
     self.logger.set_level(10)
     with dcs.capture_output() as out:
         is_valid = dcs.validate_opti_opts(self.opti_opts)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(is_valid)
     self.assertEqual(output,'******************************\nValidating optimization options.')
 def test_ignore_zeros3(self):
     self.data = np.zeros(self.data.shape)
     with dcs.capture_output() as out:
         not_a_fig = dcs.plot_multiline_history(self.time, self.data, label='All Zeros', ignore_empties=True)
     output = out.getvalue().strip()
     out.close()
     self.assertIs(not_a_fig, None)
     self.assertEqual(output,'All Zeros plot skipped due to missing data.')
Beispiel #46
0
 def test_no_logging(self):
     self.logger.set_level(0)
     with dcs.capture_output() as out:
         convergence = dcs.bpe._check_for_convergence(self.opti_opts, 0.5, 1.5, 2.5)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(convergence)
     self.assertEqual(output, '')
Beispiel #47
0
 def test_upscale(self):
     with capture_output() as out:
         dip.convert_tif_to_jpg(self.folder,
                                max_width=self.size4,
                                max_height=self.size4,
                                enlarge=True,
                                replace=True)
     output = out.getvalue().strip()
     out.close()
     lines = output.split('\n')
     self.assertTrue(output.startswith('Processing folder: "'))
     self.assertTrue(output.endswith('Batch processing complete.'))
     for this_line in lines:
         if this_line.startswith(' Saving image    : "'):
             break
     else:
         self.assertTrue(False, 'No images were saved.')
     for this_line in lines:
         if this_line.startswith(' Skipping file   : "{}"'.format(
                 self.name6)):
             break
     else:
         self.assertTrue(False,
                         'File "{}" was not skipped.'.format(self.name6))
     with open(
             os.path.join(self.folder, self.name1.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size, [self.size4, self.size4])
     fact = self.size2 / self.size1
     with open(
             os.path.join(self.folder, self.name2.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size,
                                   [int(self.size4 * fact), self.size4])
     with open(
             os.path.join(self.folder, self.name3.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(
         img.size, [self.size4, int(self.size4 * fact)])
     with open(
             os.path.join(self.folder, self.name4.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size, [self.size4, self.size6 * 2])
     with open(
             os.path.join(self.folder, self.name5.replace('.tif', '.jpg')),
             'rb') as file:
         img = Image.open(file)
         img.load()
     np.testing.assert_array_equal(img.size, [self.size6 * 2, self.size4])
     img.close()
Beispiel #48
0
 def test_nominal(self):
     with capture_output() as out:
         dip.find_unexpected_ext(self.folder)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(
         output.startswith(
             'Finding any unexpected file extensions...\n Unexpected: "'))
     self.assertTrue(output.endswith('"\nDone.'))
Beispiel #49
0
 def test_convergence4(self):
     with dcs.capture_output() as out:
         convergence = dcs.bpe._check_for_convergence(self.opti_opts, 0.5, 1.5, 2.5)
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertTrue(convergence)
     self.assertEqual(lines[0], 'Declare convergence because cosmax of 0.5 <= options.tol_cosmax_grad of 1')
     self.assertEqual(lines[1], 'Declare convergence because delta_step_len of 1.5 <= options.tol_delta_step of 2')
     self.assertEqual(lines[2], 'Declare convergence because abs(pred_func_change) of 2.5 <= options.tol_delta_cost of 3')
Beispiel #50
0
 def test_nominal(self):
     with capture_output() as out:
         dip.rename_upper_ext(self.folder)
     output = out.getvalue().strip()
     out.close()
     self.assertTrue(
         output.startswith(
             'Searching for file extensions to rename...\n Renaming: "'))
     self.assertTrue(output.endswith('\nDone.'))
Beispiel #51
0
 def test_printing(self):
     with dcs.capture_output() as out:
         print(self.current_results)
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertEqual(lines[0], 'Current Results:')
     self.assertEqual(lines[1], '  Trust Radius: None')
     self.assertEqual(lines[2], '  Best Cost: None')
     self.assertEqual(lines[3], '  Best Params: None')
Beispiel #52
0
 def test_is_new(self):
     solutions = self.solutions[:]
     self.assertEqual(len(solutions), 1)
     with capture_output() as out:
         fiver._save_solution(solutions, self.this_board2)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(len(solutions), 2)
     self.assertEqual(output, 'Solution 2 found!')
 def test_pprint(self):
     truth = dcs.TruthPlotter(self.x, self.y+0.01, lo=self.y, hi=self.y+0.03)
     with dcs.capture_output() as out:
         truth.pprint()
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertEqual(lines[0], 'TruthPlotter')
     self.assertTrue(lines[1].startswith(' time    = ['))
     self.assertEqual(lines[-1], ' name    = Observed')
Beispiel #54
0
 def test_print(self):
     c1 = dcs.Counter(1)
     with dcs.capture_output() as out:
         print(c1)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '1')
     output = repr(c1)
     self.assertEqual(output, 'Counter(1)')
Beispiel #55
0
 def test_duplicated_funcs(self):
     with open(self.filepath, 'wt') as file:
         file.write('def Test_Frozen():\n    pass\n')
     with dcs.capture_output() as out:
         text = dcs.make_python_init(self.folder2)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(text[0:39], 'from .temp_file      import Test_Frozen')
     self.assertTrue(output.startswith('Uniqueness Problem'))
Beispiel #56
0
 def test_bad_reading(self):
     with dcs.capture_output() as out:
         try:
             dcs.read_text_file(self.badpath)
         except:
             self.assertTrue(sys.exc_info()[0] in [OSError, IOError, FileNotFoundError])
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, r'Unable to open file "AA:\non_existent_path\bad_file.txt" for reading.')
Beispiel #57
0
 def test_two_different_lists(self):
     c1 = [1]
     c2 = [1]
     with dcs.capture_output() as out:
         is_same = dcs.compare_two_classes(c1, c2, ignore_callables=True)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(output, '"c1" and "c2" are the same.')
     self.assertTrue(is_same)
Beispiel #58
0
 def test_max(self):
     with capture_output() as out:
         moves = knight.solve_max_puzzle(self.board)
     output = out.getvalue().strip()
     out.close()
     self.assertEqual(moves, self.moves)
     expected_output_start = 'Initializing solver.\nSolution found for cost of: 8.'
     self.assertEqual(output[:len(expected_output_start)],
                      expected_output_start)