def test_postaladdress_as_tsv():
    item = Item()
    item.streetAddress = "Aviation House, 125 Kingsway"
    item.addressLocality = "Holborn"
    item.addressRegion = "London"
    item.postcode = "WC2B 6NH"
    item.addressCountry = "GB"

    data = item.tsv
    assert data == (
        "addressCountry\taddressLocality\taddressRegion\tpostcode\tstreetAddress\n"  # NOQA
        "GB\tHolborn\tLondon\tWC2B 6NH\tAviation House, 125 Kingsway\n"  # NOQA
    )
def test_postaladdress_as_csv():
    item = Item()
    item.streetAddress = "Aviation House, 125 Kingsway"
    item.addressLocality = "Holborn"
    item.addressRegion = "London"
    item.postcode = "WC2B 6NH"
    item.addressCountry = "GB"

    data = item.csv
    assert data == (
        '"addressCountry","addressLocality","addressRegion","postcode","streetAddress"\r\n'  # NOQA
        '"GB","Holborn","London","WC2B 6NH","Aviation House, 125 Kingsway"\r\n'  # NOQA
    )
def test_postaladdress_as_txt():
    item = Item()
    item.streetAddress = "Aviation House, 125 Kingsway"
    item.addressLocality = "Holborn"
    item.addressRegion = "London"
    item.postcode = "WC2B 6NH"
    item.addressCountry = "GB"

    data = item.txt
    assert data == ("addressCountry: GB\n"
                    "addressLocality: Holborn\n"
                    "addressRegion: London\n"
                    "postcode: WC2B 6NH\n"
                    "streetAddress: Aviation House, 125 Kingsway\n")
Beispiel #4
0
def test_postaladdress_as_jsonl():
    item = Item()
    item.streetAddress = "Aviation House, 125 Kingsway"
    item.addressLocality = "Holborn"
    item.addressRegion = "London"
    item.postcode = "WC2B 6NH"
    item.addressCountry = "GB"

    data = item.json
    assert data == ('{"addressCountry":"GB",'
                    '"addressLocality":"Holborn",'
                    '"addressRegion":"London",'
                    '"postcode":"WC2B 6NH",'
                    '"streetAddress":"Aviation House, 125 Kingsway"}')
Beispiel #5
0
def test_postaladdress_as_primitive():
    item = Item()
    item.streetAddress = "Aviation House, 125 Kingsway"
    item.addressLocality = "Holborn"
    item.addressRegion = "London"
    item.postcode = "WC2B 6NH"
    item.addressCountry = "GB"

    assert item.primitive == {
        "addressCountry": "GB",
        "addressLocality": "Holborn",
        "addressRegion": "London",
        "postcode": "WC2B 6NH",
        "streetAddress": "Aviation House, 125 Kingsway",
    }
Beispiel #6
0
def test_postaladdress_as_primitive():
    item = Item()
    item.streetAddress = "Aviation House, 125 Kingsway"
    item.addressLocality = "Holborn"
    item.addressRegion = "London"
    item.postcode = "WC2B 6NH"
    item.addressCountry = "GB"

    assert item.primitive == {
        'addressCountry': 'GB',
        'addressLocality': 'Holborn',
        'addressRegion': 'London',
        'postcode': 'WC2B 6NH',
        'streetAddress': 'Aviation House, 125 Kingsway'
    }
    def open(self, prefix):
        self.prefix = prefix
        filename = os.path.join(self.dirname, self.prefix + '.tsv')
        self.writer = Writer(open(filename, "w"), self.fieldnames)
        print("writing %s .." % filename)

    def close(self):
        if self.writer:
            self.writer.close()


reader = csv.DictReader(sys.stdin)
reader.fieldnames = [field.strip() for field in reader.fieldnames]

writer = PostcodeWriter(dirname)

for row in reader:

    item = Item()
    item.postcode = row['pcds']

    try:
        item.point = osgb_point(row['oseast1m'], row['osnrth1m'])
    except TypeError:
        pass

    writer.write(item)

writer.close()