PyPaf 1.0.1__tar.gz → 1.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {pypaf-1.0.1/src/PyPaf.egg-info → pypaf-1.0.3}/PKG-INFO +1 -1
  2. {pypaf-1.0.1 → pypaf-1.0.3/src/PyPaf.egg-info}/PKG-INFO +1 -1
  3. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/__init__.py +5 -0
  4. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/building_type.py +12 -2
  5. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/exception.py +4 -0
  6. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/split.py +13 -0
  7. pypaf-1.0.3/src/paf/version.py +3 -0
  8. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_3.py +80 -0
  9. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_6.py +85 -0
  10. pypaf-1.0.1/src/paf/version.py +0 -3
  11. {pypaf-1.0.1 → pypaf-1.0.3}/LICENSE.txt +0 -0
  12. {pypaf-1.0.1 → pypaf-1.0.3}/README.md +0 -0
  13. {pypaf-1.0.1 → pypaf-1.0.3}/pyproject.toml +0 -0
  14. {pypaf-1.0.1 → pypaf-1.0.3}/setup.cfg +0 -0
  15. {pypaf-1.0.1 → pypaf-1.0.3}/src/PyPaf.egg-info/SOURCES.txt +0 -0
  16. {pypaf-1.0.1 → pypaf-1.0.3}/src/PyPaf.egg-info/dependency_links.txt +0 -0
  17. {pypaf-1.0.1 → pypaf-1.0.3}/src/PyPaf.egg-info/top_level.txt +0 -0
  18. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/__init__.py +0 -0
  19. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/address.py +0 -0
  20. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/attribute.py +0 -0
  21. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/immutable.py +0 -0
  22. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/initiator.py +0 -0
  23. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/lineable.py +0 -0
  24. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/attribute.py +0 -0
  25. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/dependent_premisable.py +0 -0
  26. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/extender.py +0 -0
  27. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/lineable.py +0 -0
  28. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/premisable.py +0 -0
  29. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule000.py +0 -0
  30. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule001.py +0 -0
  31. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule010.py +0 -0
  32. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule011.py +0 -0
  33. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule100.py +0 -0
  34. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule101.py +0 -0
  35. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule110.py +0 -0
  36. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/premises/rule111.py +0 -0
  37. {pypaf-1.0.1 → pypaf-1.0.3}/src/paf/thoroughfare_locality.py +0 -0
  38. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_empty.py +0 -0
  39. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_exception_i.py +0 -0
  40. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_exception_ii.py +0 -0
  41. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_exception_iii.py +0 -0
  42. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_exception_iv.py +0 -0
  43. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_immutability.py +0 -0
  44. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_kwargs.py +0 -0
  45. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_mainfile.py +0 -0
  46. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_po_box.py +0 -0
  47. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_premises.py +0 -0
  48. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_1.py +0 -0
  49. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_2.py +0 -0
  50. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_4.py +0 -0
  51. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_5.py +0 -0
  52. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_7.py +0 -0
  53. {pypaf-1.0.1 → pypaf-1.0.3}/tests/test_rule_x.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyPaf
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: Formats the elements of a Royal Mail Postcode Address File entry
5
5
  Author-email: John Bard <johnbard@globalnet.co.uk>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyPaf
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: Formats the elements of a Royal Mail Postcode Address File entry
5
5
  Author-email: John Bard <johnbard@globalnet.co.uk>
6
6
  License: MIT
@@ -94,6 +94,11 @@ class Premises(
94
94
  """Returns last word of the building name"""
95
95
  return self.last_word('building_name')
96
96
 
97
+ @property
98
+ def building_name_last_two_words(self):
99
+ """Returns last two words of the building name"""
100
+ return self.last_two_words('building_name')
101
+
97
102
  @property
98
103
  def sub_building_name_but_last_word(self):
99
104
  """Returns all but last word of the sub-building name"""
@@ -15,14 +15,20 @@ class BuildingTypeMixin(SplitMixin):
15
15
  "MAISONETTE", "MAISONETTES", "REAR OF",
16
16
  "SHOP", "SHOPS", "STALL", "STALLS",
17
17
  "SUITE", "SUITES", "UNIT", "UNITS",
18
- "PO BOX"
18
+ "FLAT", "FLATS", "PO BOX"
19
19
  )
20
20
 
21
21
  @classmethod
22
22
  @property
23
23
  def known_sub_building_types(cls):
24
24
  """Returns known sub-building types"""
25
- return cls.known_building_types + ("FLAT", "FLATS")
25
+ return cls.known_building_types
26
+
27
+ @classmethod
28
+ @property
29
+ def known_split_building_types(cls):
30
+ """Returns known split building types"""
31
+ return ("UNIT",)
26
32
 
27
33
  def is_known_building_type(self, attr='building_name'):
28
34
  """Returns if attribute starts with a known type"""
@@ -31,3 +37,7 @@ class BuildingTypeMixin(SplitMixin):
31
37
  def is_known_sub_building_type(self, attr='sub_building_name'):
32
38
  """Returns if attribute starts with a known type"""
33
39
  return self.but_last_word(attr) in self.known_sub_building_types
40
+
41
+ def is_known_split_building_type(self, attr='building_name'):
42
+ """Returns if attribute starts with a known type"""
43
+ return self.but_last_word(attr) in self.known_split_building_types
@@ -50,4 +50,8 @@ class ExceptionMixin(BuildingTypeMixin, SplitMixin):
50
50
  or self.__is_exception_ii(self.last_word(attr)))
51
51
  and not self.last_word(attr).isdigit()
52
52
  and not self.__is_exception_iv(attr)
53
+ and (
54
+ attr != 'building_name'
55
+ or not self.is_known_split_building_type('building_name_last_two_words')
56
+ )
53
57
  )
@@ -24,6 +24,15 @@ class SplitMixin():
24
24
  except ValueError:
25
25
  return string
26
26
 
27
+ @classmethod
28
+ def __last_two_words(cls, string):
29
+ """Returns last two words of the string"""
30
+ try:
31
+ *_, penultimate, last = string.split()
32
+ return ' '.join([penultimate, last])
33
+ except ValueError:
34
+ return cls.__last_word(string)
35
+
27
36
  @classmethod
28
37
  def __leading_digits(cls, string):
29
38
  """Returns the leading digits from the string"""
@@ -49,6 +58,10 @@ class SplitMixin():
49
58
  """Returns last word of the attribute"""
50
59
  return self.__last_word(str(getattr(self, attr, '')))
51
60
 
61
+ def last_two_words(self, attr):
62
+ """Returns last two word of the attribute"""
63
+ return self.__last_two_words(str(getattr(self, attr, '')))
64
+
52
65
  def leading_digits(self, attr):
53
66
  """Returns the leading digits from the attribute"""
54
67
  return self.__leading_digits(str(getattr(self, attr, '')))
@@ -0,0 +1,3 @@
1
+ """Version"""
2
+
3
+ __version__ = '1.0.3'
@@ -349,5 +349,85 @@ class TestRule3WithoutCharSplit(unittest.TestCase):
349
349
  )
350
350
 
351
351
 
352
+ class TestRule3WithoutTypeSplit(unittest.TestCase):
353
+ """Test Address Rule 3 without Building Type Split Exception"""
354
+
355
+ @classmethod
356
+ def setUpClass(cls):
357
+ """Set up Address instance"""
358
+ cls.address = paf.Address({
359
+ 'organisation_name': "P S G MARINE & LOGISTICS LTD",
360
+ 'building_name': "PORT SERVICES HOUSE UNIT 14A",
361
+ 'thoroughfare_name': "PETERSEAT",
362
+ 'thoroughfare_descriptor': "DRIVE",
363
+ 'dependent_locality': "ALTENS INDUSTRIAL ESTATE",
364
+ 'post_town': "ABERDEEN",
365
+ 'postcode': "AB12 3HT"
366
+ })
367
+
368
+ def test_list(self):
369
+ """Test conversion to an list"""
370
+ address = [
371
+ "P S G MARINE & LOGISTICS LTD",
372
+ "PORT SERVICES HOUSE UNIT 14A",
373
+ "PETERSEAT DRIVE",
374
+ "ALTENS INDUSTRIAL ESTATE",
375
+ "ABERDEEN",
376
+ "AB12 3HT"
377
+ ]
378
+ self.assertEqual(
379
+ self.address.as_list(), address, "Incorrect Rule 3 w/o type split list format"
380
+ )
381
+
382
+ def test_string(self):
383
+ """Test conversion to a string"""
384
+ address = (
385
+ "P S G MARINE & LOGISTICS LTD, "
386
+ "PORT SERVICES HOUSE UNIT 14A, "
387
+ "PETERSEAT DRIVE, "
388
+ "ALTENS INDUSTRIAL ESTATE, "
389
+ "ABERDEEN. "
390
+ "AB12 3HT"
391
+ )
392
+ self.assertEqual(
393
+ self.address.as_str(), address, "Incorrect Rule 3 w/o type split string format"
394
+ )
395
+
396
+ def test_tuple(self):
397
+ """Test conversion to a tuple"""
398
+ address = (
399
+ "P S G MARINE & LOGISTICS LTD",
400
+ "PORT SERVICES HOUSE UNIT 14A",
401
+ "PETERSEAT DRIVE",
402
+ "ALTENS INDUSTRIAL ESTATE",
403
+ "ABERDEEN",
404
+ "AB12 3HT"
405
+ )
406
+ self.assertEqual(
407
+ self.address.as_tuple(), address, "Incorrect Rule 3 w/o type split tuple format"
408
+ )
409
+
410
+ def test_dict(self):
411
+ """Test conversion to a dict"""
412
+ address = {
413
+ 'line_1': "P S G MARINE & LOGISTICS LTD",
414
+ 'line_2': "PORT SERVICES HOUSE UNIT 14A",
415
+ 'line_3': "PETERSEAT DRIVE",
416
+ 'line_4': "ALTENS INDUSTRIAL ESTATE",
417
+ 'post_town': "ABERDEEN",
418
+ 'postcode': "AB12 3HT"
419
+ }
420
+ self.assertEqual(
421
+ self.address.as_dict(), address, "Incorrect Rule 3 w/o type split dict format"
422
+ )
423
+
424
+ def test_premises(self):
425
+ """Test premises"""
426
+ premises = {'premises_name': 'PORT SERVICES HOUSE UNIT 14A'}
427
+ self.assertEqual(
428
+ self.address.premises(), premises, "Incorrect Rule 3 w/o type split premises"
429
+ )
430
+
431
+
352
432
  if __name__ == '__main__':
353
433
  unittest.main()
@@ -286,6 +286,91 @@ class TestRule6WithDoubleException(unittest.TestCase):
286
286
  self.address.premises(), premises, "Incorrect Rule 6 w/ split building premises")
287
287
 
288
288
 
289
+ class TestRule6WithBuilding(unittest.TestCase):
290
+ """Test Address Rule 6 with Building Non-Exception"""
291
+
292
+ @classmethod
293
+ def setUpClass(cls):
294
+ """Set up Address instance"""
295
+ cls.address = paf.Address({
296
+ 'sub_building_name': "FLAT 1",
297
+ 'building_name': "SUNLIFE BUILDING 1A",
298
+ 'thoroughfare_name': "SOUTH VIEW",
299
+ 'thoroughfare_descriptor': "PLACE",
300
+ 'dependent_locality': "MIDSOMER NORTON",
301
+ 'post_town': "RADSTOCK",
302
+ 'postcode': "BA3 2AX"
303
+ })
304
+
305
+ def test_list(self):
306
+ """Test conversion to an list"""
307
+ address = [
308
+ "FLAT 1",
309
+ "SUNLIFE BUILDING",
310
+ "1A SOUTH VIEW PLACE",
311
+ "MIDSOMER NORTON",
312
+ "RADSTOCK",
313
+ "BA3 2AX"
314
+ ]
315
+ self.assertEqual(
316
+ self.address.as_list(), address, "Incorrect Rule 6 w/ building non list format"
317
+ )
318
+
319
+ def test_string(self):
320
+ """Test conversion to a string"""
321
+ address = (
322
+ "FLAT 1, "
323
+ "SUNLIFE BUILDING, "
324
+ "1A SOUTH VIEW PLACE, "
325
+ "MIDSOMER NORTON, "
326
+ "RADSTOCK. "
327
+ "BA3 2AX"
328
+ )
329
+ self.assertEqual(
330
+ self.address.as_str(), address, "Incorrect Rule 6 w/ building non string format"
331
+ )
332
+
333
+ def test_tuple(self):
334
+ """Test conversion to a tuple"""
335
+ address = (
336
+ "FLAT 1",
337
+ "SUNLIFE BUILDING",
338
+ "1A SOUTH VIEW PLACE",
339
+ "MIDSOMER NORTON",
340
+ "RADSTOCK",
341
+ "BA3 2AX"
342
+ )
343
+ self.assertEqual(
344
+ self.address.as_tuple(), address, "Incorrect Rule 6 w/ building non tuple format"
345
+ )
346
+
347
+ def test_dict(self):
348
+ """Test conversion to a dict"""
349
+ address = {
350
+ 'line_1': "FLAT 1",
351
+ 'line_2': "SUNLIFE BUILDING",
352
+ 'line_3': "1A SOUTH VIEW PLACE",
353
+ 'line_4': "MIDSOMER NORTON",
354
+ 'post_town': "RADSTOCK",
355
+ 'postcode': "BA3 2AX"
356
+ }
357
+ self.assertEqual(
358
+ self.address.as_dict(), address, "Incorrect Rule 6 w/ building non dict format"
359
+ )
360
+
361
+ def test_premises(self):
362
+ """Test premises"""
363
+ premises = {
364
+ 'premises_number': 1,
365
+ 'premises_suffix': 'A',
366
+ 'premises_name': 'SUNLIFE BUILDING',
367
+ 'sub_premises_type': 'FLAT',
368
+ 'sub_premises_number': 1
369
+ }
370
+ self.assertEqual(
371
+ self.address.premises(), premises, "Incorrect Rule 6 w/ building non premises")
372
+
373
+
289
374
  class TestRule6(unittest.TestCase):
290
375
  """Test Address Rule 6 without Exception"""
291
376
 
@@ -1,3 +0,0 @@
1
- """Version"""
2
-
3
- __version__ = '1.0.1'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes