def test_output_archive_same(self): ''' Tests when output and archive directory are explicitly set to the same path. ''' file_q = FileQueue(self.input_path, self.archive_path, self.queue_path, self.archive_path) test_file = os.path.join(self.input_path, 'test_file.txt') with open(test_file, 'w') as file_: file_.write('test text') file_q.check_dir() # if output Path is none, the files would show up in the archive path self.assertFalse(os.path.isfile(test_file)) base_name = os.path.basename(test_file) # in queue now self.assertTrue( os.path.isfile(os.path.join(self.queue_path, base_name))) # pop file output = file_q.pop(addtimestamp=False) self.assertEqual(os.path.join(self.archive_path, base_name), output)
def test_check_dir(self): ''' Does it check the input directory as expected? Does this push all files found to the queue_path? ''' # create FileQueue file_q = FileQueue(self.input_path, self.output_path, self.queue_path, self.archive_path) # create test file and push to the queue test_file = os.path.join(self.input_path, 'test_file.txt') with open(test_file, 'w') as file_: file_.write('test text') self.assertTrue(os.path.isfile(test_file)) file_q.check_dir() # checks the input_path for any files and pushes # them should have one item on it and it should be the test_file but it # should be on the queue queue_file = os.path.join(self.queue_path, os.path.basename(test_file)) self.assertTrue(os.path.isfile(queue_file)) self.assertFalse(os.path.isfile(test_file)) with open(queue_file, 'r') as file_: line = file_.read() self.assertEqual(line, 'test text')
def test_empty_output_path(self): ''' If no output path specified, does it change the archive location? ''' file_q = FileQueue(self.input_path, None, self.queue_path, self.archive_path) test_file = os.path.join(self.input_path, 'test_file.txt') with open(test_file, 'w') as file_: file_.write('test text') file_q.check_dir() # if output Path is none, the files would show up in the archive path self.assertFalse(os.path.isfile(test_file)) base_name = os.path.basename(test_file) # in queue now self.assertTrue( os.path.isfile(os.path.join(self.queue_path, base_name))) # pop file output = file_q.pop() self.assertEqual( os.path.join(self.archive_path, os.path.basename(output)), output)