def test_specified_file(self): root_dir = DATA_DIR with self.assertLogs('lowatt.collect', level='INFO') as cm: postcollect( root_dir, self.sources, {}, [ datafile('s1', 'f1.csv'), join(THIS_DIR, 'whatever'), datafile('s2', 'f2.csv'), datafile('s3', 'unexisting'), ], ) self.assertEqual( sorted(msg.replace(THIS_DIR + '/', '') for msg in cm.output), [ "ERROR:lowatt.collect:Can't find source for file " "data/s3/unexisting", "ERROR:lowatt.collect:File whatever isn't under " 'root (data)', 'ERROR:lowatt.collect:Source s2 for file data/s2/f2.csv has ' 'no postcollect command', ], )
def test_postcollect_no_postcollect_args(self): with TemporaryDirectory() as tmpdir: makedirs(join(tmpdir, 's1')) open(join(tmpdir, 's1', 's1.file'), 'w').write('') postcollect( tmpdir, { 's1': { 'postcollect': '{HERE}/echofile.py {DIR}/s1.file postcollect', # noqa }, }, env={ 'TEST': 'test', 'HERE': dirname(__file__) }, postcollect_args=False, ) with open(join(tmpdir, 's1', 's1.file')) as stream: self.assertEqual( stream.readline().strip(), 'postcollect', ) self.assertEOF(stream)
def test_specified_source(self): root_dir = DATA_DIR with self.assertLogs('lowatt.collect', level='DEBUG') as cm: postcollect(root_dir, self.sources, {}, ['s1']) self.assertEqual( sorted(msg.replace(THIS_DIR + '/', '') for msg in cm.output), [ 'DEBUG:lowatt.collect:post collecting 1 files for source s1', ], )
def test(self): root_dir = DATA_DIR with self.assertLogs('lowatt.collect', level='INFO') as cm: errors = postcollect(root_dir, self.sources, {}) self.assertEqual( sorted(msg.replace(root_dir + '/', '') for msg in cm.output), [ 'ERROR:lowatt.collect:No postcollect command to handle ' 's2/f2.csv', 'ERROR:lowatt.collect:No source matching s1/unknown directory', ], ) self.assertEqual(len(errors), 0)