def test_all_present_with_custom_frames(self):
     testargs = 'foo.py -filename 1_a_###.mrc  -frames_dir {} -first_last 1,2'
     testargs = testargs.format(self.tempdir).split()
     with patch('sys.argv', testargs):                
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         self.assertTrue(obj.check_all_present(l))
 def test(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     exp = [os.path.join(self.tempdir, i) for i in self.testfiles].sort()
     with patch('sys.argv', testargs):
         obj = m()
         obj.frames_dir = self.tempdir
     self.assertEqual(exp, obj.get_minimal_set(obj.get_file_list()).sort())
 def test(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     exp = [os.path.join(self.tempdir, i) for i in self.testfiles].sort()
     with patch('sys.argv', testargs):
         obj = m()
         obj.frames_dir = self.tempdir
     self.assertEqual(exp, obj.get_minimal_set(obj.get_file_list()).sort())
 def test_all_present_with_custom_frames(self):
     testargs = 'foo.py -filename 1_a_###.mrc  -frames_dir {} -first_last 1,2'
     testargs = testargs.format(self.tempdir).split()
     with patch('sys.argv', testargs):
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         self.assertTrue(obj.check_all_present(l))
 def test_missing_frames_no_force(self):
     testargs = 'foo.py -filename 1_a_###.mrc -frames_dir {}'.format(self.tempdir)
     testargs = testargs.split()
     for i in (self.testfiles_missing):
         f= open(os.path.join(self.tempdir, i), 'w')
     with patch('sys.argv', testargs):                
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         with self.assertRaises(SystemExit):
             obj.check_all_present(l)    
 def test_missing_frames_with_custom_frames_no_force(self):
     testargs = 'foo.py -filename 1_a_###.mrc -frames_dir {} -first_last 4,6'
     testargs = testargs.format(self.tempdir).split()
     for i in ['1_a_002_frames_n6.mrc', '1_a_002_frames_n5.mrc']:
         open(i, 'w')
         f = open(os.path.join(self.tempdir, i), 'w')
     with patch('sys.argv', testargs):
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         with self.assertRaises(SystemExit):
             obj.check_all_present(l)
 def test_missing_frames_with_custom_frames_no_force(self):
     testargs = 'foo.py -filename 1_a_###.mrc -frames_dir {} -first_last 4,6'
     testargs = testargs.format(self.tempdir).split()
     for i in ['1_a_002_frames_n6.mrc','1_a_002_frames_n5.mrc']:
         open(i,'w')
         f= open(os.path.join(self.tempdir, i), 'w')
     with patch('sys.argv', testargs):                
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         with self.assertRaises(SystemExit):
             obj.check_all_present(l)
 def test_missing_frames_no_force(self):
     testargs = 'foo.py -filename 1_a_###.mrc -frames_dir {}'.format(
         self.tempdir)
     testargs = testargs.split()
     for i in (self.testfiles_missing):
         f = open(os.path.join(self.tempdir, i), 'w')
     with patch('sys.argv', testargs):
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         with self.assertRaises(SystemExit):
             obj.check_all_present(l)
 def test_missing_frames_with_custom_frames_and_force(self):
     testargs = 'foo.py -filename 1_a_###.mrc -frames_dir {} -first_last 4,6 -f'
     testargs = testargs.format(self.tempdir).split()
     for i in ['1_a_002_frames_n6.mrc', '1_a_002_frames_n5.mrc']:
         open(i, 'w')
         f = open(os.path.join(self.tempdir, i), 'w')
     exp = [os.path.join(self.tempdir, '1_a_002_frames_n4.mrc')]
     with patch('sys.argv', testargs):
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         self.assertFalse(obj.check_all_present(l))
         self.assertEqual(exp.sort(), obj.missing.sort())
 def test_missing_frames_with_custom_frames_and_force(self):
     testargs = 'foo.py -filename 1_a_###.mrc -frames_dir {} -first_last 4,6 -f'
     testargs = testargs.format(self.tempdir).split()
     for i in ['1_a_002_frames_n6.mrc','1_a_002_frames_n5.mrc']:
         open(i,'w')
         f= open(os.path.join(self.tempdir, i), 'w')
     exp = [os.path.join(self.tempdir, '1_a_002_frames_n4.mrc')]
     with patch('sys.argv', testargs):                
         obj = m()
         l = obj.get_minimal_set(obj.get_file_list())
         self.assertFalse(obj.check_all_present(l))
         self.assertEqual(exp.sort(), obj.missing.sort())
 def test_digits_count(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(3, obj.digits)
 def test_digits_count(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(3, obj.digits)
 def test_first_last_frame_number_no_comma(self):
     testargs = 'foo.py -filename 1_a_#.mrc -first_last 1 2'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_no_frame_specification_default(self):
     testargs = 'foo.py -filename 1_a_#.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(0, obj.first_frame)
         self.assertEqual(6, obj.last_frame)
 def test_micrograph_name(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual('1_a_{}', obj.micrograph_name) 
 def test_frame_name(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual('1_a_{}_frames_n{}', obj.frame_name)
 def test_default_frame_suffix(self):
     testargs = 'foo.py -filename 1_a_#.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         exp = 'frames_n{}'
         self.assertEqual(exp, obj.frames_suffix)
 def test_output_dir_creation(self):
     testargs = 'foo.py -filename 1_a_#.mrc -output_dir /tmp/tmp'.split()
     with patch('sys.argv', testargs):
         with patch('os.makedirs') as mock:
             obj = m()
             self.assertTrue(mock.called)
 def test_default_output_dir(self):
     testargs = 'foo.py -filename 1_a_#.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(obj.frames_dir, obj.output_dir)
 def test_nonexisting_input_dir(self):
     testargs = 'foo.py -filename 1_a_#.mrc -frames_dir /not/exists'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_no_hash_in_filename(self):
     testargs = 'foo.py -filename 1_a_.mrc'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_nonexisting_input_dir(self):
     testargs = 'foo.py -filename 1_a_#.mrc -frames_dir /not/exists'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_micrograph_name(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual('1_a_{}', obj.micrograph_name)
 def test_output_dir_creation(self):
     testargs = 'foo.py -filename 1_a_#.mrc -output_dir /tmp/tmp'.split()
     with patch('sys.argv', testargs):
         with patch('os.makedirs') as mock:
             obj = m()
             self.assertTrue(mock.called)
 def test_no_hash_in_filename(self):
     testargs = 'foo.py -filename 1_a_.mrc'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_no_hash_in_frame_suffix(self):
     testargs = 'foo.py -filename 1_a_#.mrc -frames_suffix _n'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_no_hash_in_frame_suffix(self):
     testargs = 'foo.py -filename 1_a_#.mrc -frames_suffix _n'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_frame_name(self):
     testargs = 'foo.py -filename 1_a_###.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual('1_a_{}_frames_n{}', obj.frame_name)
 def test_non_frames_suffix_starting_underscore(self):
     testargs = 'foo.py -filename 1_a_#.mrc -frames_suffix _n#'.split()
     with patch('sys.argv', testargs):
         obj = m()
         exp = 'n{}'
         self.assertEqual(exp, obj.frames_suffix)
 def test_no_frame_specification_default(self):
     testargs = 'foo.py -filename 1_a_#.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(0, obj.first_frame)
         self.assertEqual(6, obj.last_frame)
 def test_default_output_dir(self):
     testargs = 'foo.py -filename 1_a_#.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(obj.frames_dir, obj.output_dir)
 def test_first_last_frame(self):
     testargs = 'foo.py -filename 1_a_#.mrc -first_last 1,2'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(1, obj.first_frame)
         self.assertEqual(2, obj.last_frame)
 def test_default_frame_suffix(self):
     testargs = 'foo.py -filename 1_a_#.mrc'.split()
     with patch('sys.argv', testargs):
         obj = m()
         exp = 'frames_n{}'
         self.assertEqual(exp, obj.frames_suffix)
 def test_first_last_frame_number_no_comma(self):
     testargs = 'foo.py -filename 1_a_#.mrc -first_last 1 2'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(SystemExit):
             obj = m()
 def test_non_frames_suffix_starting_underscore(self):
     testargs = 'foo.py -filename 1_a_#.mrc -frames_suffix _n#'.split()
     with patch('sys.argv', testargs):
         obj = m()
         exp = 'n{}'
         self.assertEqual(exp, obj.frames_suffix)
 def test_n_frames(self):
     testargs = 'foo.py -filename 1_a_#.mrc -n_frames 12'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(0, obj.first_frame)
         self.assertEqual(11, obj.last_frame)
 def test_first_last_frame(self):
     testargs = 'foo.py -filename 1_a_#.mrc -first_last 1,2'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(1, obj.first_frame)
         self.assertEqual(2, obj.last_frame)
 def test_first_last_not_a_number(self):
     testargs = 'foo.py -filename 1_a_#.mrc -first_last a,b'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(ValueError):
             obj = m()
 def test_n_frames(self):
     testargs = 'foo.py -filename 1_a_#.mrc -n_frames 12'.split()
     with patch('sys.argv', testargs):
         obj = m()
         self.assertEqual(0, obj.first_frame)
         self.assertEqual(11, obj.last_frame)
 def test_first_last_not_a_number(self):
     testargs = 'foo.py -filename 1_a_#.mrc -first_last a,b'.split()
     with patch('sys.argv', testargs):
         with self.assertRaises(ValueError):
             obj = m()