# Path: tecs/rinex/label.py
# SAT_SYS_GPS = 'G'
# 
# SAT_SYS_GAL = 'E'  # Galileo
# 
# Path: tecs/rinex/nmutils.py
# def compose_navigation_re(system, epoch):
#     """
# 
#     Parameters
#     ----------
#     system : str
#         satellite system code
#     epoch : datetime.datetime
#         date & time
# 
#     Returns
#     --------
#     re : re.Pattern
#     """
#     nav_id = {
#         SAT_SYS_GPS: 'n',
#         SAT_SYS_GLO: 'g',
#         SAT_SYS_GEO: 'h',
#         SAT_SYS_GAL: 'l',
#         SAT_SYS_MIX: 'p'
#     }
# 
#     classic_nav_tmpl = r'^(\w{{4}}){day}\w\.{year}{system}'
# 
#     modern_nav_tmpl = (
#         '^(\w{{4}})'
#         '\w{{5}}'
#         '_\w_'
#         '{year}{day}\d{{4}}'
#         '_\w{{3}}'
#         '(_\w{{3}})?'
#         '_{system}N\.rnx'
#     )
# 
#     modern_nav = modern_nav_tmpl.format(year=epoch.strftime('%Y'),
#                                         day=epoch.strftime('%j'),
#                                         system=system)
# 
#     if system in nav_id:
#         # classic and modern name style
#         classic_nav = classic_nav_tmpl.format(day=epoch.strftime('%j'),
#                                               year=epoch.strftime('%y'),
#                                               system=nav_id[system])
# 
#         re_str = '{classic} | {modern}'.format(classic=classic_nav,
#                                                modern=modern_nav)
#     else:
#         # modern name only
#         re_str = modern_nav
# 
#     return re.compile(re_str, (re.I | re.X))


import datetime
from tecs.rinex.label import SAT_SYS_GPS, SAT_SYS_GAL
from tecs.rinex.nmutils import compose_navigation_re
from __future__ import unicode_literals




NAME = 'tecs.tests.test_nmutils'


def test_compose_navigation_re():
    nav_file_v2 = 'cebr1000.16l.Z'
    nav_file_v3 = 'CEBR00ESP_R_20161000000_01D_EN.rnx.gz'

    epoch = datetime.datetime(2016, 4, 9)
    system = SAT_SYS_GAL

    re_nav = compose_navigation_re(system, epoch)

    assert re_nav.match(nav_file_v2)
    assert re_nav.match(nav_file_v3)

    epoch = datetime.datetime(2016, 4, 10)
    system = SAT_SYS_GPS

    re_nav = compose_navigation_re(system, epoch)

    assert not re_nav.match(nav_file_v2)
    assert not re_nav.match(nav_file_v3)

    nav_file_v3_df = 'ISTP00RUS_R_20160010000_01H_50Z_GN.rnx'
    epoch = datetime.datetime(2016, 1, 1)

# Path: tecs/rinex/label.py
# SAT_SYS_GPS = 'G'
# 
# SAT_SYS_GAL = 'E'  # Galileo
# 
# Path: tecs/rinex/nmutils.py
# def compose_navigation_re(system, epoch):
#     """
# 
#     Parameters
#     ----------
#     system : str
#         satellite system code
#     epoch : datetime.datetime
#         date & time
# 
#     Returns
#     --------
#     re : re.Pattern
#     """
#     nav_id = {
#         SAT_SYS_GPS: 'n',
#         SAT_SYS_GLO: 'g',
#         SAT_SYS_GEO: 'h',
#         SAT_SYS_GAL: 'l',
#         SAT_SYS_MIX: 'p'
#     }
# 
#     classic_nav_tmpl = r'^(\w{{4}}){day}\w\.{year}{system}'
# 
#     modern_nav_tmpl = (
#         '^(\w{{4}})'
#         '\w{{5}}'
#         '_\w_'
#         '{year}{day}\d{{4}}'
#         '_\w{{3}}'
#         '(_\w{{3}})?'
#         '_{system}N\.rnx'
#     )
# 
#     modern_nav = modern_nav_tmpl.format(year=epoch.strftime('%Y'),
#                                         day=epoch.strftime('%j'),
#                                         system=system)
# 
#     if system in nav_id:
#         # classic and modern name style
#         classic_nav = classic_nav_tmpl.format(day=epoch.strftime('%j'),
#                                               year=epoch.strftime('%y'),
#                                               system=nav_id[system])
# 
#         re_str = '{classic} | {modern}'.format(classic=classic_nav,
#                                                modern=modern_nav)
#     else:
#         # modern name only
#         re_str = modern_nav
# 
#     return re.compile(re_str, (re.I | re.X))


# Path: tecs/tests/test_nmutils.py
import datetime
from tecs.rinex.label import SAT_SYS_GPS, SAT_SYS_GAL
from tecs.rinex.nmutils import compose_navigation_re

from __future__ import unicode_literals




NAME = 'tecs.tests.test_nmutils'


def test_compose_navigation_re():
    nav_file_v2 = 'cebr1000.16l.Z'
    nav_file_v3 = 'CEBR00ESP_R_20161000000_01D_EN.rnx.gz'

    epoch = datetime.datetime(2016, 4, 9)
    system = SAT_SYS_GAL

    re_nav = compose_navigation_re(system, epoch)

    assert re_nav.match(nav_file_v2)
    assert re_nav.match(nav_file_v3)

    epoch = datetime.datetime(2016, 4, 10)
    system = SAT_SYS_GPS

    re_nav = compose_navigation_re(system, epoch)

    assert not re_nav.match(nav_file_v2)
    assert not re_nav.match(nav_file_v3)

    nav_file_v3_df = 'ISTP00RUS_R_20160010000_01H_50Z_GN.rnx'
    epoch = datetime.datetime(2016, 1, 1)

    system = SAT_SYS_GPS