# Path: tibanna/top.py
# class Top(object):
# class Process(object):             
#     def __init__(self, contents):
#     def parse_contents(self, contents):
#     def digest(self, max_n_commands=16, sort_by='alphabetical'):
#     def get_collapsed_commands(self, max_n_commands):
#     def write_to_csv(self, csv_file, metric='cpu', delimiter=',', colname_for_timestamps='timepoints',
#                      timestamp_start=None, timestamp_end=None, base=0):
#     def should_skip_process(self, process):
#     def convert_command_to_collapsed_command(cmd, collapsed_commands):
#     def total_cpu_per_command(self, command):
#     def total_mem_per_command(self, command):
#     def sort_commands(self, by='cpu'):
#     def as_minutes(cls, timestamp, timestamp_start):
#     def timestamps_as_minutes(self, timestamp_start):
#     def as_datetime(cls, timestamp):
#     def wrap_in_double_quotes(string):
#     def first_words(string, n_words):
#     def first_characters(string, n_letters):
#     def as_dict(self):
#     def __init__(self, top_line):
#     def as_dict(self):


import os
from tibanna import top
    assert len(lines) == 4
    assert lines[0] == 'timepoints\t\"bwa mem\"\t\"java -jar somejar.jar\"'
    assert lines[1] == '1\t0\t0'
    assert lines[2] == '2\t0\t9.9'
    assert lines[3] == '3\t0\t0'

    top1.write_to_csv(test_tsv_file, metric='mem', base=1, timestamp_start='2020-12-18-18:54:37', timestamp_end='2020-12-18-18:56:37')
    with open(test_tsv_file) as f:
        content = f.read()
    lines = content.splitlines()
    assert len(lines) == 4
    assert lines[0] == 'timepoints,\"bwa mem\",\"java -jar somejar.jar\"'
    assert lines[1] == '1,0,0'
    assert lines[2] == '2,13.0,8.9'
    assert lines[3] == '3,0,0'

    top1.write_to_csv(test_tsv_file, metric='mem', base=1, timestamp_start='2020-12-18-18:53:02', timestamp_end='2020-12-18-18:56:22')
    with open(test_tsv_file) as f:
        content = f.read()
    lines = content.splitlines()
    assert len(lines) == 5
    assert lines[0] == 'timepoints,\"bwa mem\",\"java -jar somejar.jar\"'
    assert lines[1] == '1,0,0'  # 18:53:02
    assert lines[2] == '2,0,0'  # 18:54:02
    assert lines[3] == '3,0,0'  # 18:55:02
    assert lines[4] == '4,13.0,8.9'  # 18:56:02 <- 18:55:37 (first entry), 18:56:22 (end time) are rounded to this one.

    os.remove(test_tsv_file)

def test_wrap_in_double_quotes():

# Path: tibanna/top.py
# class Top(object):
# class Process(object):             
#     def __init__(self, contents):
#     def parse_contents(self, contents):
#     def digest(self, max_n_commands=16, sort_by='alphabetical'):
#     def get_collapsed_commands(self, max_n_commands):
#     def write_to_csv(self, csv_file, metric='cpu', delimiter=',', colname_for_timestamps='timepoints',
#                      timestamp_start=None, timestamp_end=None, base=0):
#     def should_skip_process(self, process):
#     def convert_command_to_collapsed_command(cmd, collapsed_commands):
#     def total_cpu_per_command(self, command):
#     def total_mem_per_command(self, command):
#     def sort_commands(self, by='cpu'):
#     def as_minutes(cls, timestamp, timestamp_start):
#     def timestamps_as_minutes(self, timestamp_start):
#     def as_datetime(cls, timestamp):
#     def wrap_in_double_quotes(string):
#     def first_words(string, n_words):
#     def first_characters(string, n_letters):
#     def as_dict(self):
#     def __init__(self, top_line):
#     def as_dict(self):


# Path: tests/tibanna/unicorn/test_top.py
import os
from tibanna import top

    assert len(lines) == 4
    assert lines[0] == 'timepoints\t\"bwa mem\"\t\"java -jar somejar.jar\"'
    assert lines[1] == '1\t0\t0'
    assert lines[2] == '2\t0\t9.9'
    assert lines[3] == '3\t0\t0'

    top1.write_to_csv(test_tsv_file, metric='mem', base=1, timestamp_start='2020-12-18-18:54:37', timestamp_end='2020-12-18-18:56:37')
    with open(test_tsv_file) as f:
        content = f.read()
    lines = content.splitlines()
    assert len(lines) == 4
    assert lines[0] == 'timepoints,\"bwa mem\",\"java -jar somejar.jar\"'
    assert lines[1] == '1,0,0'
    assert lines[2] == '2,13.0,8.9'
    assert lines[3] == '3,0,0'

    top1.write_to_csv(test_tsv_file, metric='mem', base=1, timestamp_start='2020-12-18-18:53:02', timestamp_end='2020-12-18-18:56:22')
    with open(test_tsv_file) as f:
        content = f.read()
    lines = content.splitlines()
    assert len(lines) == 5
    assert lines[0] == 'timepoints,\"bwa mem\",\"java -jar somejar.jar\"'
    assert lines[1] == '1,0,0'  # 18:53:02
    assert lines[2] == '2,0,0'  # 18:54:02
    assert lines[3] == '3,0,0'  # 18:55:02
    assert lines[4] == '4,13.0,8.9'  # 18:56:02 <- 18:55:37 (first entry), 18:56:22 (end time) are rounded to this one.

    os.remove(test_tsv_file)

def test_wrap_in_double_quotes():

    haha = top.Top.wrap_in_double_quotes('haha')