Example #1
0
    def test_write_lines(self):
        with TempDirectory() as output_file:
            writer = FileWriter(os.path.join(output_file.path, "A.tmp"))
            writer.open()
            writer.write("1\n2\n")
            writer.write("3")
            writer.close()

            actual_file = open(os.path.join(output_file.path, "A.tmp"))
            actual_output = actual_file.readlines()
            actual_file.close()

            self.assertEquals(["1\n", "2\n", "3"], actual_output)
Example #2
0
    def test_write_lines(self):
        with TempDirectory() as output_file:
            writer = FileWriter(os.path.join(output_file.path, "A.tmp"))
            writer.open()
            writer.write("1\n2\n")
            writer.write("3")
            writer.close()

            actual_file = open(os.path.join(output_file.path, "A.tmp"))
            actual_output = actual_file.readlines()
            actual_file.close()

            self.assertEquals(["1\n", "2\n", "3"], actual_output)
Example #3
0
    def test_write(self):
        with TempDirectory() as output_file:
            file_path = os.path.join(output_file.path, "test.tmp")

            writer = FileWriter(file_path)
            writer.open()
            writer.write("A")
            writer.write("B\n")
            writer.write("CD\n")
            writer.close()

            actual_output = output_file.read('test.tmp', encoding='utf8')
            expected_output = "AB|CD|".replace('|', os.linesep)
            self.assertEquals(expected_output, actual_output)
Example #4
0
    def test_write(self):
        with TempDirectory() as output_file:
            file_path = os.path.join(output_file.path, "test.tmp")

            writer = FileWriter(file_path)
            writer.open()
            writer.write("A")
            writer.write("B\n")
            writer.write("CD\n")
            writer.close()

            actual_output = output_file.read("test.tmp", encoding="utf8")
            expected_output = "AB|CD|".replace("|", os.linesep)
            self.assertEquals(expected_output, actual_output)
Example #5
0
def _sort_vcf(reader, sorted_dir):
    vcf_records = []
    reader.open()
    for vcf_record in reader.vcf_records():
        vcf_records.append(vcf_record)

    reader.close()
    vcf_records.sort()
    writer = FileWriter(os.path.join(sorted_dir, reader.file_name))
    writer.open()
    writer.write("\n".join(reader.metaheaders) + "\n")
    writer.write(reader.column_header + "\n")
    for vcf_record in vcf_records:
        writer.write(vcf_record.text())

    writer.close()
    reader = MergeVcfReader(vcf.FileReader(writer.output_filepath))
    return reader
Example #6
0
def _sort_vcf(reader, sorted_dir):
    vcf_records = []
    reader.open()
    for vcf_record in reader.vcf_records():
        vcf_records.append(vcf_record)

    reader.close()
    vcf_records.sort()
    writer = FileWriter(os.path.join(sorted_dir,
                                     reader.file_name))
    writer.open()
    writer.write("\n".join(reader.metaheaders) + "\n")
    writer.write(reader.column_header + "\n")
    for vcf_record in vcf_records:
        writer.write(vcf_record.text())

    writer.close()
    reader = MergeVcfReader(vcf.FileReader(writer.output_filepath))
    return reader