Ejemplo n.º 1
0
class TestDirectory(object):

    def setup(self):

        chp_csv_lines = '''郵遞區號,縣市名稱,鄉鎮市區,原始路名,投遞範圍
10058,臺北市,中正區,八德路1段,全
10079,臺北市,中正區,三元街,單全
10070,臺北市,中正區,三元街,雙  48號以下
10079,臺北市,中正區,三元街,雙  50號以上
10068,臺北市,中正區,大埔街,單  15號以上
10068,臺北市,中正區,大埔街,雙  36號以上
10051,臺北市,中正區,中山北路1段,單   3號以下
10041,臺北市,中正區,中山北路1段,雙  48號以下
10051,臺北市,中正區,中山南路,單   5號以下
10041,臺北市,中正區,中山南路,雙  18號以下
10002,臺北市,中正區,中山南路,    7號
10051,臺北市,中正區,中山南路,    9號
10048,臺北市,中正區,中山南路,單  11號以上
10001,臺北市,中正區,中山南路,   20號
10043,臺北市,中正區,中華路1段,單  25之   3號以下
10042,臺北市,中正區,中華路1段,單  27號至  47號
10010,臺北市,中正區,中華路1段,   49號
10042,臺北市,中正區,中華路1段,單  51號以上
10065,臺北市,中正區,中華路2段,單  79號以下
10066,臺北市,中正區,中華路2段,單  81號至 101號
10068,臺北市,中正區,中華路2段,單 103號至 193號
10069,臺北市,中正區,中華路2段,單 195號至 315號
10067,臺北市,中正區,中華路2段,單 317號至 417號
10072,臺北市,中正區,中華路2段,單 419號以上
10055,臺北市,中正區,丹陽街,全
10051,臺北市,中正區,仁愛路1段,    1號
10052,臺北市,中正區,仁愛路1段,連   2之   4號以上
10055,臺北市,中正區,仁愛路2段,單  37號以下
10060,臺北市,中正區,仁愛路2段,雙  48號以下
10056,臺北市,中正區,仁愛路2段,單  39號至  49號
10056,臺北市,中正區,仁愛路2段,雙  48之   1號至  64號
10062,臺北市,中正區,仁愛路2段,單  51號以上
10063,臺北市,中正區,仁愛路2段,雙  66號以上'''.split('\n')

        self.dir_ = Directory()
        self.dir_.load_chp_csv(chp_csv_lines)

    def test_find_zipcodes(self):

        assert self.dir_.find_zipcodes('臺北市') == ['10058', '10079', '10070', '10079', '10068', '10068', '10051', '10041', '10051', '10041', '10002', '10051', '10048', '10001', '10043', '10042', '10010', '10042', '10065', '10066', '10068', '10069', '10067', '10072', '10055', '10051', '10052', '10055', '10060', '10056', '10056', '10062', '10063']
        assert self.dir_.find_zipcodes('臺北市中正區') == ['10058', '10079', '10070', '10079', '10068', '10068', '10051', '10041', '10051', '10041', '10002', '10051', '10048', '10001', '10043', '10042', '10010', '10042', '10065', '10066', '10068', '10069', '10067', '10072', '10055', '10051', '10052', '10055', '10060', '10056', '10056', '10062', '10063']
        assert self.dir_.find_zipcodes('臺北市中正區仁愛路1段') == ['10051', '10052']
        assert self.dir_.find_zipcodes('臺北市中正區仁愛路1段1號') == ['10051']

    def test_find(self):

        assert self.dir_.find('臺北市') == '100'
        assert self.dir_.find('臺北市中正區') == '100'
        assert self.dir_.find('臺北市中正區仁愛路1段') == '1005'
        assert self.dir_.find('臺北市中正區仁愛路1段1號') == '10051'
Ejemplo n.º 2
0
    def setup(self):

        chp_csv_lines = '''郵遞區號,縣市名稱,鄉鎮市區,原始路名,投遞範圍
10058,臺北市,中正區,八德路1段,全
10079,臺北市,中正區,三元街,單全
10070,臺北市,中正區,三元街,雙  48號以下
10079,臺北市,中正區,三元街,雙  50號以上
10068,臺北市,中正區,大埔街,單  15號以上
10068,臺北市,中正區,大埔街,雙  36號以上
10051,臺北市,中正區,中山北路1段,單   3號以下
10041,臺北市,中正區,中山北路1段,雙  48號以下
10051,臺北市,中正區,中山南路,單   5號以下
10041,臺北市,中正區,中山南路,雙  18號以下
10002,臺北市,中正區,中山南路,    7號
10051,臺北市,中正區,中山南路,    9號
10048,臺北市,中正區,中山南路,單  11號以上
10001,臺北市,中正區,中山南路,   20號
10043,臺北市,中正區,中華路1段,單  25之   3號以下
10042,臺北市,中正區,中華路1段,單  27號至  47號
10010,臺北市,中正區,中華路1段,   49號
10042,臺北市,中正區,中華路1段,單  51號以上
10065,臺北市,中正區,中華路2段,單  79號以下
10066,臺北市,中正區,中華路2段,單  81號至 101號
10068,臺北市,中正區,中華路2段,單 103號至 193號
10069,臺北市,中正區,中華路2段,單 195號至 315號
10067,臺北市,中正區,中華路2段,單 317號至 417號
10072,臺北市,中正區,中華路2段,單 419號以上
10055,臺北市,中正區,丹陽街,全
10051,臺北市,中正區,仁愛路1段,    1號
10052,臺北市,中正區,仁愛路1段,連   2之   4號以上
10055,臺北市,中正區,仁愛路2段,單  37號以下
10060,臺北市,中正區,仁愛路2段,雙  48號以下
10056,臺北市,中正區,仁愛路2段,單  39號至  49號
10056,臺北市,中正區,仁愛路2段,雙  48之   1號至  64號
10062,臺北市,中正區,仁愛路2段,單  51號以上
10063,臺北市,中正區,仁愛路2段,雙  66號以上'''.split('\n')

        self.dir_ = Directory()
        self.dir_.load_chp_csv(chp_csv_lines)
Ejemplo n.º 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from os.path import dirname, join
from _zipcodetw import Directory, __version__

_ROOT = dirname(__file__)

_dir = Directory()
_dir.load_chp_csv(open(join(_ROOT, '201311.csv')))

find_zipcodes = _dir.find_zipcodes
find = _dir.find