def testThree(self): """ The take function must return three items at a time if passed n=3, and also return the extra two items. """ self.assertEqual([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10]], list(take(range(11), 3)))
def testNBiggerThanPassedList(self): """ The take function must return all items if passed an n that is bigger than the passed list. """ self.assertEqual([[3, 4, 5]], list(take([3, 4, 5], 100)))
def testOne(self): """ The take function must return individual items if passed n=1. """ self.assertEqual([[3], [4], [5]], list(take([3, 4, 5], 1)))
def testEmpty(self): """ The take function must return an empty generator if passed an empty list. """ self.assertEqual([], list(take([], 4)))
def testNLessThanOne(self): """ The take function must raise an AssertionError if passed n < 1. list. """ self.assertRaises(AssertionError, next, take([], 0))
if not exists(args.outDir): mkdir(args.outDir) saveAs = (args.saveAs or (args.fasta and 'fasta') or (args.fastq and 'fastq') or (args.fasta_ss and 'fasta-ss')) # Note: we may be reading the FASTA input from stdin, so we cannot read it # more than once (and I don't want to store it all because it may be very # large). That's why we do a second phase of processing to renumber the # files we created (if --noLeadingZeroes is not used). outDir = Path(args.outDir) count = 0 for count, reads in enumerate(take(parseFASTACommandLineOptions(args), args.count), start=1): filename = outDir / f'{count}.fasta' if not args.force and filename.exists(): print( f'Will not overwrite pre-existing file {str(filename)!r}. ' f'Use --force to make me. Exiting.', file=sys.stderr) sys.exit(1) if args.verbose: print(f'Writing {filename}') with open(filename, 'w') as fp: Reads(reads).save(fp, saveAs) # Rename numeric filenames to have leading zeroes. if count and not args.noLeadingZeroes: