def test_i_pattern(self): self.tempdir = tempfile.mkdtemp() testargs = 'foo.py -i *.mrc -o @.mrc' with patch('sys.argv', testargs.split()): a = m.imageConverter() self.assertEqual(a.i, '*.mrc') self.assertEqual(self.files, a.files)
def test_process_given_with_A(self): testargs = 'foo.py --lowpass 40A' with patch('sys.argv', testargs.split()): a = m.imageConverter() i = 1/40 exp = '--process filter.lowpass.gauss:cutoff_freq={}'.format(i) self.assertAlmostEqual(a.lowpass, exp, 7, 0.001)
def test_ncpus_too_many(self): testargs = 'foo.py --n_cpus 200000000' with patch('sys.argv', testargs.split()): with self.assertRaises(SystemExit): m.imageConverter()
def test_ncpus_given_and_ok(self): testargs = 'foo.py --n_cpus 4' with patch('sys.argv', testargs.split()): a = m.imageConverter() self.assertEqual(a.n_cpus, 4)
def test_ncpus_default(self): testargs = 'foo.py' cpus = multiprocessing.cpu_count() -1 with patch('sys.argv', testargs.split()): a = m.imageConverter() self.assertEqual(a.n_cpus, cpus)
def test_scale_given(self): testargs = 'foo.py --scale 4' with patch('sys.argv', testargs.split()): a = m.imageConverter() self.assertEqual(a.scale, '--meanshrink 4')
def test_scale_default(self): with patch('sys.argv', ['foo.py']): a = m.imageConverter() self.assertEqual(a.scale, '')
def test_process_given_malformed(self): testargs = 'foo.py --lowpass forty' with patch('sys.argv', testargs.split()): with self.assertRaises(SystemExit): m.imageConverter()
def test_process_default(self): with patch('sys.argv', ['foo.py']): a = m.imageConverter() self.assertEqual(a.lowpass, '')
def test_o_given_nonexisting_no_force(self): testargs = 'foo.py -o /nonexisting/path' with patch('sys.argv', testargs.split()): with patch('os.makedirs'): with self.assertRaises(SystemExit): m.imageConverter()
def test_o_exists_and_no_force(self): testargs = 'foo.py -i {0} -o @_hig -f'.format(self.tempdir) with patch('sys.argv', testargs.split()): with patch ('os.makedirs') as mock: m.imageConverter() self.assertTrue(mock.called)
def test_o_given_and_same_as_i(self): testargs = 'foo.py -i {0} -o {0} -'.format(self.files[0]) with patch('sys.argv', testargs.split()): with self.assertRaises(SystemExit): m.imageConverter()
def test_o_pattern(self): testargs = 'foo.py -i {} -o @.mrc'.format(self.files[0]) with patch('sys.argv', testargs.split()): a = m.imageConverter() exp = os.path.join('@.mrc') self.assertEqual(exp, a.o)
def test_o_single_file(self): testargs = 'foo.py -i {} -o testout.mrc'.format(self.files[0]) with patch('sys.argv', testargs.split()): a = m.imageConverter() exp = os.path.join(self.tempdir, 'testout.mrc') self.assertEqual(exp, a.o)
def test_i_single_file(self): testargs = 'foo.py -i {} -o @.mrc'.format(self.files[0]) with patch('sys.argv', testargs): print(sys.argv) a = m.imageConverter() self.assertEqual(self.files[0], a.i)