# Path: nanpy/fwinfo.py
# def libc_version(AVR_LIBC_VERSION):
#     """
#     Example: 10604  -> 1.6.4
# 
#     """
#     s = str(AVR_LIBC_VERSION)
#     ls = [s[0], s[1:3], s[3:5]]
#     ls = map(int, ls)
#     ls = map(str, ls)
#     return '.'.join(ls)
# 
# def arduino_version(ARDUINO):
#     """
#     Example: 105  -> 1.0.5
#     10608 -> 1.6.8
#     """
#     s = str(ARDUINO)
#     if len(s) == 5:
#         return '%s.%s.%s' % (s[0], int(s[1:3]), int(s[3:5]))
#     else:
#         return '.'.join(s)
# 
# def avr_name(MCU):
#     """The name of the AVR.
# 
#     Example: __AVR_ATmega328P__ -> ATmega328P
# 
#     """
#     return MCU.strip('_').split('_')[-1]
# 
# def libc_date(AVR_LIBC_DATE):
#     """
#     Example: 20081106  -> 2008.11.06
# 
#     """
#     s = str(AVR_LIBC_DATE)
#     ls = [s[0:4], s[4:6], s[6:8]]
#     ls = map(int, ls)
#     d = datetime.date(*ls)
#     return d
# 
# def compile_datetime(DATE, TIME):
#     '''
#     Example: Mar 28 2014, 17:40:12
#     -> datetime.datetime(2008, 3, 28, 17, 40, 12)
#     '''
#     dls = DATE.strip().split()
#     d = datetime.date(int(dls[2]), parse_month(dls[0]), int(dls[1]))
#     t = datetime.datetime.strptime(TIME, '%H:%M:%S')
#     dt = datetime.datetime.combine(d, t.time())
# #     dt = datetime.datetime.strptime(
# #         DATE + ' ' + TIME,
# #         '%b %d %Y %H:%M:%S')
#     return dt
# 
# def firmware_info(define_dict):
#     d = dict()
#     d['avr_name'] = avr_name(define_dict['MCU'])
#     d['arduino_version'] = arduino_version(define_dict['ARDUINO'])
#     d['compile_datetime'] = compile_datetime(define_dict['__DATE__'],
#                                              define_dict['__TIME__'],
#                                              )
#     d['gcc_version'] = define_dict['__VERSION__']
#     d['libc_version'] = libc_version(define_dict['__AVR_LIBC_VERSION__'])
#     d['libc_date'] = libc_date(define_dict['__AVR_LIBC_DATE_'])
# 
#     return d


from nanpy.fwinfo import libc_version, arduino_version, avr_name, libc_date, \
    compile_datetime, firmware_info
from nose.tools import eq_
import datetime


def test():
    eq_(libc_version(10604), '1.6.4')
    eq_(libc_version('10604'), '1.6.4')
    eq_(libc_version(11111), '1.11.11')

    eq_(libc_date(20081106), datetime.date(2008, 11, 6))
    eq_(libc_date('20081106'), datetime.date(2008, 11, 6))

    eq_(arduino_version(105), '1.0.5')
    eq_(arduino_version('105'), '1.0.5')
    eq_(arduino_version(10608), '1.6.8')
    eq_(arduino_version('10608'), '1.6.8')
    eq_(arduino_version('52417'), '5.24.17')

    eq_(avr_name('__AVR_ATmega328P__'), 'ATmega328P')

    eq_(compile_datetime('Mar 28 2008', '17:40:12'),
        datetime.datetime(2008, 3, 28, 17, 40, 12))
    eq_(compile_datetime('Apr 10 2016', '15:54:18'),
        datetime.datetime(2016, 4, 10, 15, 54, 18))


# Path: nanpy/fwinfo.py
# def libc_version(AVR_LIBC_VERSION):
#     """
#     Example: 10604  -> 1.6.4
# 
#     """
#     s = str(AVR_LIBC_VERSION)
#     ls = [s[0], s[1:3], s[3:5]]
#     ls = map(int, ls)
#     ls = map(str, ls)
#     return '.'.join(ls)
# 
# def arduino_version(ARDUINO):
#     """
#     Example: 105  -> 1.0.5
#     10608 -> 1.6.8
#     """
#     s = str(ARDUINO)
#     if len(s) == 5:
#         return '%s.%s.%s' % (s[0], int(s[1:3]), int(s[3:5]))
#     else:
#         return '.'.join(s)
# 
# def avr_name(MCU):
#     """The name of the AVR.
# 
#     Example: __AVR_ATmega328P__ -> ATmega328P
# 
#     """
#     return MCU.strip('_').split('_')[-1]
# 
# def libc_date(AVR_LIBC_DATE):
#     """
#     Example: 20081106  -> 2008.11.06
# 
#     """
#     s = str(AVR_LIBC_DATE)
#     ls = [s[0:4], s[4:6], s[6:8]]
#     ls = map(int, ls)
#     d = datetime.date(*ls)
#     return d
# 
# def compile_datetime(DATE, TIME):
#     '''
#     Example: Mar 28 2014, 17:40:12
#     -> datetime.datetime(2008, 3, 28, 17, 40, 12)
#     '''
#     dls = DATE.strip().split()
#     d = datetime.date(int(dls[2]), parse_month(dls[0]), int(dls[1]))
#     t = datetime.datetime.strptime(TIME, '%H:%M:%S')
#     dt = datetime.datetime.combine(d, t.time())
# #     dt = datetime.datetime.strptime(
# #         DATE + ' ' + TIME,
# #         '%b %d %Y %H:%M:%S')
#     return dt
# 
# def firmware_info(define_dict):
#     d = dict()
#     d['avr_name'] = avr_name(define_dict['MCU'])
#     d['arduino_version'] = arduino_version(define_dict['ARDUINO'])
#     d['compile_datetime'] = compile_datetime(define_dict['__DATE__'],
#                                              define_dict['__TIME__'],
#                                              )
#     d['gcc_version'] = define_dict['__VERSION__']
#     d['libc_version'] = libc_version(define_dict['__AVR_LIBC_VERSION__'])
#     d['libc_date'] = libc_date(define_dict['__AVR_LIBC_DATE_'])
# 
#     return d


# Path: tests/test_offline/test_fwinfo.py
from nanpy.fwinfo import libc_version, arduino_version, avr_name, libc_date, \
    compile_datetime, firmware_info
from nose.tools import eq_
import datetime



def test():
    eq_(libc_version(10604), '1.6.4')
    eq_(libc_version('10604'), '1.6.4')
    eq_(libc_version(11111), '1.11.11')

    eq_(libc_date(20081106), datetime.date(2008, 11, 6))
    eq_(libc_date('20081106'), datetime.date(2008, 11, 6))

    eq_(arduino_version(105), '1.0.5')
    eq_(arduino_version('105'), '1.0.5')
    eq_(arduino_version(10608), '1.6.8')
    eq_(arduino_version('10608'), '1.6.8')
    eq_(arduino_version('52417'), '5.24.17')

    eq_(avr_name('__AVR_ATmega328P__'), 'ATmega328P')

    eq_(compile_datetime('Mar 28 2008', '17:40:12'),
        datetime.datetime(2008, 3, 28, 17, 40, 12))
    eq_(compile_datetime('Apr 10 2016', '15:54:18'),
        datetime.datetime(2016, 4, 10, 15, 54, 18))


    eq_(firmware_info(dict(