def test_command_factory_ignores_non_existing_paths(self): # Given. cf = CommandFactory(dest=self.root1, input_extension='.py', output_extension='.rst', command="echo $input $output") p = Project(name='test', path=self.root) p.scan() os.remove(os.path.join(self.root, 'hello.py')) # When jobs = cf.make_jobs(p.keys(), p) # Then. self.assertEqual(len(jobs), 0)
def test_command_factory_commands(self): # Given. cf = CommandFactory(dest=self.root1, input_extension='.py', output_extension='.rst', command="echo $input $output") p = Project(name='test', path=self.root) p.scan() # When jobs = cf.make_jobs(p.keys(), p) # Then. self.assertEqual(len(jobs), 1) job = jobs[0] m = p.get('hello.py') dest = os.path.join(self.root1, 'hello.rst') expect = ('echo %s %s' % (m.path, dest)).replace('\\', '\\\\') self.assertEqual(job.args, [expect.split(), m.path, dest])
def test_command_factory_jobs(self): # Given. import sys command = """\ %r -c 'import shutil;shutil.copy("$input", "$output")'\ """ % sys.executable cf = CommandFactory(dest=self.root1, input_extension='.py', output_extension='.rst', command=command, copy_timestamps=True) p = Project(name='test', path=self.root) p.scan() # When jobs = cf.make_jobs(p.keys(), p) job = jobs[0] job.run() job.thread.join() # Then. self.assertEqual(len(jobs), 1) self.assertEqual(job.status, 'success') m = p.get('hello.py') dest = os.path.join(self.root1, 'hello.rst') self.assertTrue(os.path.exists(dest)) self.assertEqual(cf._done[dest], True) s_stat = os.stat(m.path) d_stat = os.stat(dest) self.assertTrue(abs(s_stat.st_mtime - d_stat.st_mtime) < 2) self.assertTrue(abs(s_stat.st_ctime - d_stat.st_ctime) < 2) jobs = cf.make_jobs(p.keys(), p) self.assertEqual(len(jobs), 0) # When. data = dump(cf) cf1 = load(data) # Then. for attr in cf.__dict__.keys(): self.assertEqual(getattr(cf1, attr), getattr(cf, attr))
def test_project_copy_does_not_copy_data(self): # Given tags = [TagInfo(name='completed', type='bool'), TagInfo(name='comment', type='string')] p = Project(name='test', path=self.root, extensions=['.txt', '.py'], tags=tags) cf = CommandFactory(dest=self.root, input_extension='.py', output_extension='.rst', command='echo $input $output') p.processors = [cf] p.scan() # Update the _done trait the processors to check if it is copied. m = p.get('root.txt') cf._done[m.path] = True # When p1 = p.copy() # Then self.assertEqual(p.number_of_files, 5) self.assertEqual(p1.number_of_files, 0) self.assertEqual(p1.name, p.name + ' copy') self.assertEqual(p1.path, p.path) tag_info = [(x.name, x.type) for x in p.tags] tag_info1 = [(x.name, x.type) for x in p1.tags] self.assertEqual(tag_info, tag_info1) self.assertEqual(p1.extensions, p.extensions) self.assertEqual(len(p1._relpath2index), 0) self.assertEqual(len(p1.processors), len(p.processors)) p1_proc_traits = p1.processors[0].trait_get() p1_proc_traits.pop('_done') p_proc_traits = p.processors[0].trait_get() p_proc_traits.pop('_done') self.assertEqual(p1_proc_traits, p_proc_traits) self.assertEqual(len(p.processors[0]._done), 1) self.assertEqual(len(p1.processors[0]._done), 0) # When p.tags[0].type = 'int' # Then # This just checks that p1's tags are not a reference to p's. self.assertEqual(p1.tags[0].type, 'bool')