def test_clean_line(self):
     dirty_line = "R\0\0 Sample line with prefix R"
     cleaned_line = clean_line(dirty_line)
     self.assertEqual(cleaned_line, " Sample line with prefix R")
     dirty_line = "Q\0\0 Sample line with prefix Q"
     cleaned_line = clean_line(dirty_line)
     self.assertEqual(cleaned_line, " Sample line with prefix Q")
conn = sqlite3.connect(config.DATABASE_NAME)
cursor = conn.cursor()

s = simple_socket.SimpleSocket()
s.connect(config.AXXESS_IP, config.AXXESS_PORT)

# Introduce ourselves
s.send("02000000".decode("hex"))
s.send("8400".decode("hex"))

# Receive data forever
while (1):
    line = s.receive(RECORD_LENGTH)

    cleaned_line = clean_line(line)

    if (raw_file is not None):
        f = open(raw_file, "a")

        if (f is not None):
            f.write(cleaned_line)
            f.close()

    cdr = line_to_cdr(cleaned_line, None) 

    if (cdr is not False):
        status = insert_cdr_record(cdr, cursor)

        if (status is 1):
            conn.commit()
fileName = basename(fileWithPath)
m        = re.match(r'phone_log_(\d+?)-(\d+?)-(\d+?)\.log', fileName)

if (m is None):
    logging.critical("Log file name is malformed.")
    logging.critical("Name must conform to phone_log_yyyy-mm-dd.log")
    sys.exit(1)

# Assemble datetime from filename
logYear  = int(m.group(1))
logMonth = int(m.group(2))
logDay   = int(m.group(3))
log_date = datetime.date(logYear, logMonth, logDay)

conn = sqlite3.connect(config.DATABASE_NAME)
cursor = conn.cursor()

f = open(fileWithPath)

for line in f:
    line = clean_line(line)
    cdr = line_to_cdr(line, log_date)
    insert_cdr_record(cdr, cursor)

f.close()

conn.commit()
conn.close()