def test_main_versionOption(self): with patch('sys.stdout', new=StringIO()) as mockStdout: sys.argv = ['sort', '--version'] sort.main() self.assertTrue( -1 != mockStdout.getvalue().find('Written by Aldebaran Perseke'))
def test_main_stdin_dictionaryOrder(self): with patch('sys.stdout', new=StringIO()) as mockStdout: with patch('sys.stdin', new=StringIO('+ghi\nab-c\ndef)\n[jkl')) as mockStdin: sys.argv = ['sort', '--dictionary-order'] sort.main() self.assertTrue('ab-c\ndef)\n+ghi\n[jkl\n' == mockStdout.getvalue())
def test_main_stdin_reverse(self): with patch('sys.stdout', new=StringIO()) as mockStdout: with patch('sys.stdin', new=StringIO('def\nabc\njkl\nghi')) as mockStdin: sys.argv = ['sort', '--reverse'] sort.main() self.assertTrue('jkl\nghi\ndef\nabc\n' == mockStdout.getvalue())
def test_main_stdin_ignoreCase(self): with patch('sys.stdout', new=StringIO()) as mockStdout: with patch('sys.stdin', new=StringIO('DEF\nabc\nJKL\nghi')) as mockStdin: sys.argv = ['sort', '--ignore-case'] sort.main() self.assertTrue('abc\nDEF\nghi\nJKL\n' == mockStdout.getvalue())
def test_main_invalidOption(self): with patch('sys.stderr', new=StringIO()) as mockStderr: with self.assertRaises(SystemExit) as exit: sys.argv = ['sort', '-a', '--reverse'] sort.main() self.assertEqual(exit.exception.code, 2) self.assertTrue( -1 != mockStderr.getvalue().find('unrecognized arguments: -a'))
def test_main_hifenAsFileNames(self): with patch('sys.stdout', new=StringIO()) as mockStdout: with patch( 'sys.stdin', new=StringIO('def\njkl\nabc\nmno\nxyz\nghi')) as mockStdin: sys.argv = ['sort', '-'] sort.main() self.assertTrue( 'abc\ndef\nghi\njkl\nmno\nxyz\n' == mockStdout.getvalue())
def test_main_stdin_ignoreLeadingBlanks(self): with patch('sys.stdout', new=StringIO()) as mockStdout: with patch( 'sys.stdin', new=StringIO(' def\n abc\n jkl\n ghi')) as mockStdin: sys.argv = ['sort', '--ignore-leading-blanks'] sort.main() self.assertTrue( ' abc\n def\n ghi\n jkl\n' == mockStdout.getvalue())
def test_main_singleFileName(self): contentFile = tempfile.NamedTemporaryFile(delete=False) contentFile.write(b'def\njkl\nabc\nmno\nxyz\nghi') contentFile.close() with patch('sys.stdout', new=StringIO()) as mockStdout: sys.argv = ['sort', contentFile.name] sort.main() self.assertTrue( 'abc\ndef\nghi\njkl\nmno\nxyz\n' == mockStdout.getvalue()) os.remove(contentFile.name)
def test_main_invalidFileName(self): # remember, a temporary file is removed after it's closed invalidFile = tempfile.NamedTemporaryFile() invalidFileName = invalidFile.name invalidFile.write(b'abcdef\nghijklm\nnopqrs\ntuvwxyz') invalidFile.close() with patch('sys.stderr', new=StringIO()) as mockStderr: sys.argv = ['sort', invalidFileName] sort.main() self.assertTrue( -1 != mockStderr.getvalue().find('No such file or directory'))
def test_main_singleFileNameAndHifen(self): contentFile = tempfile.NamedTemporaryFile(delete=False) contentFile.write(b'stuvwxyz\nmnopqr\n') contentFile.close() with patch('sys.stdout', new=StringIO()) as mockStdout: with patch('sys.stdin', new=StringIO('abcdef\nghijkl\n')) as mockStdin: sys.argv = ['sort', contentFile.name, '-'] sort.main() self.assertTrue( 'abcdef\nghijkl\nmnopqr\nstuvwxyz\n' == mockStdout.getvalue()) os.remove(contentFile.name)
def test_sample(test): n = [] times = [] for item in test: item_counter, timing = sort.main(item) n.append(item_counter) times.append(timing) return n, times
def callSort(sortFile, arguments=[]): try: if sortFile == 'sort.py': sort.main(arguments) elif sortFile == 'sortUrls.py': print(arguments) sortUrls.main(arguments) else: raise Exception('File sorting implementation not included/found.') except IOError as e: print "Error: File \"" + argv[1] + "\" not found." except IndexError as e: print errorMessage except ValueError as e: print errorMessage except KeyError as e: print errorMessage
def test_main_multipleFileNames(self): firstContentFile = tempfile.NamedTemporaryFile(delete=False) firstContentFile.write(b'stuvwxyz\nmnopqr\n') firstContentFile.close() secondContentFile = tempfile.NamedTemporaryFile(delete=False) secondContentFile.write(b'abcdef\nghijkl\n') secondContentFile.close() with patch('sys.stdout', new=StringIO()) as mockStdout: sys.argv = ['sort', firstContentFile.name, secondContentFile.name] sort.main() self.assertTrue( 'abcdef\nghijkl\nmnopqr\nstuvwxyz\n' == mockStdout.getvalue()) os.remove(firstContentFile.name) os.remove(secondContentFile.name)
def main(): usage = "Usage: vcfPytools.py [tool] [options]\n\n" + \ "Available tools:\n" + \ " annotate:\n\tAnnotate the vcf file with membership in other vcf files.\n" + \ " extract:\n\tExtract vcf records from a region.\n" + \ " filter:\n\tFilter the vcf file.\n" + \ " indel:\n\tIndel manipulation tools.\n" + \ " intersect:\n\tGenerate the intersection of two vcf files.\n" + \ " merge:\n\tMerge a list of vcf files.\n" + \ " multi:\n\tFind the intersections and unique fractions of multiple vcf files.\n" + \ " sort:\n\tSort a vcf file.\n" + \ " stats:\n\tGenerate statistics from a vcf file.\n" + \ " union:\n\tGenerate the union of two vcf files.\n" + \ " unique:\n\tGenerate the unique fraction from two vcf files.\n" + \ " validate:\n\tValidate the input vcf file.\n\n" + \ "vcfPytools.py [tool] --help for information on a specific tool." # Determine the requested tool. if len(sys.argv) > 1: tool = sys.argv[1] else: print >> sys.stderr, usage exit(1) if tool == "annotate": import annotate success = annotate.main() elif tool == "extract": import extract success = extract.main() elif tool == "filter": import filter success = filter.main() elif tool == "intersect": import intersect success = intersect.main() elif tool == "indel": import indel success = indel.main() elif tool == "multi": import multi success = multi.main() elif tool == "merge": import merge success = merge.main() elif tool == "sort": import sort success = sort.main() elif tool == "stats": import stats success = stats.main() elif tool == "union": import union success = union.main() elif tool == "unique": import unique success = unique.main() elif tool == "test": import test success = test.main() elif tool == "validate": import validate success = validate.main() elif tool == "--help" or tool == "-h" or tool == "?": print >> sys.stderr, usage else: print >> sys.stderr, "Unknown tool: ", tool print >> sys.stderr, "\n", usage exit(1) # If program completed properly, terminate. if success == 0: exit(0)
# sleep(10) print "this is child process end." else: # 父进程 # sleep(60) # 排序,生成榜单 print "this is parent process start." ppid1 = os.fork() if ppid1 == 0: pppid2 = os.fork() if pppid2 == 0: print "this is child process. run zongheng" cmdline.execute("scrapy crawl zongheng".split()) else: import time time.sleep(9) print "this is child process. run chuangshi" cmdline.execute("scrapy crawl chuangshi".split()) else: ppppid3 = os.fork() if ppppid3 == 0: import time time.sleep(6) print "this is child process. run seventeen" cmdline.execute("scrapy crawl seventeen".split()) else: sleep(300) st.main() print "this is parent process. exe st()" print "this is parent process end." except OSError, e: pass
import os import sort import pandas as pd from pylatex.utils import italic, NoEscape from pylatex.basic import NewLine from pylatex.base_classes import Arguments from pylatex import Document, Section, Itemize, Command, Package, Subsection sort.main() geometry_options = {'margin': '1in'} document = Document('.', geometry_options=geometry_options) document.packages.append(Package('hyperref')) document.preamble.append(Command('title', 'Reading List')) document.preamble.append(Command('author', 'Daniel Saunders')) document.preamble.append(Command('date', NoEscape(r'\today'))) document.append(NoEscape(r'\maketitle')) document.append('Note: Work in progress. Some dates before mid-July 2018 are approximate.') def create_read_section(document, medium): with document.create(Subsection('Read')): with document.create(Itemize()) as itemize: try: df = pd.read_csv(os.path.join(medium, 'read.csv')) except pd.errors.EmptyDataError:
def main(): usage = "Usage: vcfPytools.py [tool] [options]\n\n" + \ "Available tools:\n" + \ " annotate:\n\tAnnotate the vcf file with membership in other vcf files.\n" + \ " extract:\n\tExtract vcf records from a region.\n" + \ " filter:\n\tFilter the vcf file.\n" + \ " indel:\n\tIndel manipulation tools.\n" + \ " intersect:\n\tGenerate the intersection of two vcf files.\n" + \ " merge:\n\tMerge a list of vcf files.\n" + \ " multi:\n\tFind the intersections and unique fractions of multiple vcf files.\n" + \ " sort:\n\tSort a vcf file.\n" + \ " stats:\n\tGenerate statistics from a vcf file.\n" + \ " union:\n\tGenerate the union of two vcf files.\n" + \ " unique:\n\tGenerate the unique fraction from two vcf files.\n" + \ " validate:\n\tValidate the input vcf file.\n\n" + \ "vcfPytools.py [tool] --help for information on a specific tool." # Determine the requested tool. if len(sys.argv) > 1: tool = sys.argv[1] else: print >> sys.stderr, usage exit(1) if tool == "annotate": import annotate success = annotate.main() elif tool == "extract": import extract success = extract.main() elif tool == "filter": import filter success = filter.main() elif tool == "intersect": import intersect success = intersect.main() elif tool == "indel": import indel success = indel.main() elif tool == "multi": import multi success = multi.main() elif tool == "merge": import merge success = merge.main() elif tool == "sort": import sort success = sort.main() elif tool == "stats": import stats success = stats.main() elif tool == "union": import union success = union.main() elif tool == "unique": import unique success = unique.main() elif tool == "test": import test success = test.main() elif tool == "validate": import validate success = validate.main() elif tool == "--help" or tool == "-h" or tool == "?": print >> sys.stderr, usage else: print >> sys.stderr, "Unknown tool: ",tool print >> sys.stderr, "\n", usage exit(1) # If program completed properly, terminate. if success == 0: exit(0)