PyPaf 1.0.0__tar.gz → 1.0.1__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 (54) hide show
  1. {PyPaf-1.0.0/src/PyPaf.egg-info → pypaf-1.0.1}/PKG-INFO +2 -2
  2. {PyPaf-1.0.0 → pypaf-1.0.1/src/PyPaf.egg-info}/PKG-INFO +2 -2
  3. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/__init__.py +5 -0
  4. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/exception.py +2 -1
  5. pypaf-1.0.1/src/paf/premises/extender.py +23 -0
  6. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule110.py +7 -2
  7. pypaf-1.0.1/src/paf/version.py +3 -0
  8. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_3.py +75 -0
  9. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_6.py +70 -0
  10. PyPaf-1.0.0/src/paf/premises/extender.py +0 -26
  11. PyPaf-1.0.0/src/paf/version.py +0 -3
  12. {PyPaf-1.0.0 → pypaf-1.0.1}/LICENSE.txt +0 -0
  13. {PyPaf-1.0.0 → pypaf-1.0.1}/README.md +0 -0
  14. {PyPaf-1.0.0 → pypaf-1.0.1}/pyproject.toml +0 -0
  15. {PyPaf-1.0.0 → pypaf-1.0.1}/setup.cfg +0 -0
  16. {PyPaf-1.0.0 → pypaf-1.0.1}/src/PyPaf.egg-info/SOURCES.txt +0 -0
  17. {PyPaf-1.0.0 → pypaf-1.0.1}/src/PyPaf.egg-info/dependency_links.txt +0 -0
  18. {PyPaf-1.0.0 → pypaf-1.0.1}/src/PyPaf.egg-info/top_level.txt +0 -0
  19. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/__init__.py +0 -0
  20. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/address.py +0 -0
  21. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/attribute.py +0 -0
  22. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/immutable.py +0 -0
  23. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/initiator.py +0 -0
  24. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/lineable.py +0 -0
  25. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/attribute.py +0 -0
  26. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/building_type.py +0 -0
  27. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/dependent_premisable.py +0 -0
  28. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/lineable.py +0 -0
  29. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/premisable.py +0 -0
  30. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule000.py +0 -0
  31. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule001.py +0 -0
  32. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule010.py +0 -0
  33. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule011.py +0 -0
  34. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule100.py +0 -0
  35. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule101.py +0 -0
  36. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/rule111.py +0 -0
  37. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/premises/split.py +0 -0
  38. {PyPaf-1.0.0 → pypaf-1.0.1}/src/paf/thoroughfare_locality.py +0 -0
  39. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_empty.py +0 -0
  40. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_exception_i.py +0 -0
  41. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_exception_ii.py +0 -0
  42. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_exception_iii.py +0 -0
  43. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_exception_iv.py +0 -0
  44. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_immutability.py +0 -0
  45. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_kwargs.py +0 -0
  46. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_mainfile.py +0 -0
  47. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_po_box.py +0 -0
  48. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_premises.py +0 -0
  49. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_1.py +0 -0
  50. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_2.py +0 -0
  51. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_4.py +0 -0
  52. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_5.py +0 -0
  53. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_7.py +0 -0
  54. {PyPaf-1.0.0 → pypaf-1.0.1}/tests/test_rule_x.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: PyPaf
3
- Version: 1.0.0
3
+ Version: 1.0.1
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
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: PyPaf
3
- Version: 1.0.0
3
+ Version: 1.0.1
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
@@ -79,6 +79,11 @@ class Premises(
79
79
  """Returns sub-building number and first thoroughfare or locality"""
80
80
  return self._concatenate(('sub_building_name', 'first_thoroughfare_or_locality'))
81
81
 
82
+ @property
83
+ def sub_and_building_name_but_last_word(self):
84
+ """Returns sub-building name and but last word of the building name"""
85
+ return self._concatenate(('sub_building_name', 'building_name_but_last_word'))
86
+
82
87
  @property
83
88
  def building_name_but_last_word(self):
84
89
  """Returns all but last word of the building name"""
@@ -46,7 +46,8 @@ class ExceptionMixin(BuildingTypeMixin, SplitMixin):
46
46
  def is_split_exception(self, attr):
47
47
  """Returns if attribute should be split"""
48
48
  return (
49
- self.__is_exception(self.last_word(attr))
49
+ (self.__is_exception_i(self.last_word(attr))
50
+ or self.__is_exception_ii(self.last_word(attr)))
50
51
  and not self.last_word(attr).isdigit()
51
52
  and not self.__is_exception_iv(attr)
52
53
  )
@@ -0,0 +1,23 @@
1
+ """Premises Extender Mixin"""
2
+
3
+ import sys
4
+ import importlib
5
+
6
+
7
+ class ExtenderMixin():
8
+ """Dynamic Premises processing"""
9
+
10
+ @property
11
+ def rule(self):
12
+ """Returns premises rule class"""
13
+ rule_num = ''.join(['0' if self.is_empty(k) else '1' for k in self.building_attrs])
14
+ package_name = getattr(sys.modules[__name__], '__package__', None)
15
+ module_name = f'rule{rule_num}'
16
+ module = importlib.import_module(f'{package_name}.{module_name}')
17
+ class_name = f'Rule{rule_num}'
18
+ return getattr(module, class_name)
19
+
20
+ def extend(self):
21
+ """Dynamically extends instance with appropriate rule"""
22
+ base_cls = self.__class__
23
+ object.__setattr__(self, '__class__', type(base_cls.__name__, (base_cls, self.rule), {}))
@@ -10,6 +10,11 @@ class Rule110(PremisableMixin):
10
10
  def rule_attrs(self):
11
11
  """Returns premises list"""
12
12
  if self.is_exception('sub_building_name'):
13
+ if self.is_split_exception('building_name'):
14
+ return (
15
+ 'sub_and_building_name_but_last_word',
16
+ 'name_last_word_and_thoroughfare_or_locality'
17
+ )
13
18
  return ('sub_name_and_name',)
14
19
  if self.is_exception('building_name'):
15
20
  return ('sub_building_name', 'name_and_thoroughfare_or_locality')
@@ -24,6 +29,6 @@ class Rule110(PremisableMixin):
24
29
  def includes_first_thoroughfare_or_locality(self):
25
30
  """Returns if premises includes first thoroughfare or locality"""
26
31
  return (
27
- not self.is_exception('sub_building_name')
28
- and (self.is_exception('building_name') or self.is_split_exception('building_name'))
32
+ self.is_split_exception('building_name')
33
+ or (not self.is_exception('sub_building_name') and self.is_exception('building_name'))
29
34
  )
@@ -0,0 +1,3 @@
1
+ """Version"""
2
+
3
+ __version__ = '1.0.1'
@@ -274,5 +274,80 @@ class TestRule3WithoutSplit(unittest.TestCase):
274
274
  )
275
275
 
276
276
 
277
+ class TestRule3WithoutCharSplit(unittest.TestCase):
278
+ """Test Address Rule 3 without Character Split Exception"""
279
+
280
+ @classmethod
281
+ def setUpClass(cls):
282
+ """Set up Address instance"""
283
+ cls.address = paf.Address({
284
+ 'organisation_name': "JOBCENTRE PLUS",
285
+ 'building_name': "ABERDEEN B D C",
286
+ 'thoroughfare_name': "WELLINGTON",
287
+ 'thoroughfare_descriptor': "CIRCLE",
288
+ 'post_town': "ABERDEEN",
289
+ 'postcode': "AB99 8AB"
290
+ })
291
+
292
+ def test_list(self):
293
+ """Test conversion to an list"""
294
+ address = [
295
+ "JOBCENTRE PLUS",
296
+ "ABERDEEN B D C",
297
+ "WELLINGTON CIRCLE",
298
+ "ABERDEEN",
299
+ "AB99 8AB"
300
+ ]
301
+ self.assertEqual(
302
+ self.address.as_list(), address, "Incorrect Rule 3 w/o char split list format"
303
+ )
304
+
305
+ def test_string(self):
306
+ """Test conversion to a string"""
307
+ address = (
308
+ "JOBCENTRE PLUS, "
309
+ "ABERDEEN B D C, "
310
+ "WELLINGTON CIRCLE, "
311
+ "ABERDEEN. "
312
+ "AB99 8AB"
313
+ )
314
+ self.assertEqual(
315
+ self.address.as_str(), address, "Incorrect Rule 3 w/o char split string format"
316
+ )
317
+
318
+ def test_tuple(self):
319
+ """Test conversion to a tuple"""
320
+ address = (
321
+ "JOBCENTRE PLUS",
322
+ "ABERDEEN B D C",
323
+ "WELLINGTON CIRCLE",
324
+ "ABERDEEN",
325
+ "AB99 8AB"
326
+ )
327
+ self.assertEqual(
328
+ self.address.as_tuple(), address, "Incorrect Rule 3 w/o char split tuple format"
329
+ )
330
+
331
+ def test_dict(self):
332
+ """Test conversion to a dict"""
333
+ address = {
334
+ 'line_1': "JOBCENTRE PLUS",
335
+ 'line_2': "ABERDEEN B D C",
336
+ 'line_3': "WELLINGTON CIRCLE",
337
+ 'post_town': "ABERDEEN",
338
+ 'postcode': "AB99 8AB"
339
+ }
340
+ self.assertEqual(
341
+ self.address.as_dict(), address, "Incorrect Rule 3 w/o char split dict format"
342
+ )
343
+
344
+ def test_premises(self):
345
+ """Test premises"""
346
+ premises = {'premises_name': 'ABERDEEN B D C'}
347
+ self.assertEqual(
348
+ self.address.premises(), premises, "Incorrect Rule 3 w/o char split premises"
349
+ )
350
+
351
+
277
352
  if __name__ == '__main__':
278
353
  unittest.main()
@@ -216,6 +216,76 @@ class TestRule6WithSplitException(unittest.TestCase):
216
216
  self.address.premises(), premises, "Incorrect Rule 6 w/ split building premises")
217
217
 
218
218
 
219
+ class TestRule6WithDoubleException(unittest.TestCase):
220
+ """Test Address Rule 6 with Double Building Name Exception"""
221
+
222
+ @classmethod
223
+ def setUpClass(cls):
224
+ """Set up Address instance"""
225
+ cls.address = paf.Address({
226
+ 'sub_building_name': "91",
227
+ 'building_name': "OCEAN APARTMENTS 52-54",
228
+ 'thoroughfare_name': "PARK",
229
+ 'thoroughfare_descriptor': "ROAD",
230
+ 'post_town': "ABERDEEN",
231
+ 'postcode': "AB24 5RZ"
232
+ })
233
+
234
+ def test_list(self):
235
+ """Test conversion to an list"""
236
+ address = [
237
+ "91 OCEAN APARTMENTS",
238
+ "52-54 PARK ROAD",
239
+ "ABERDEEN",
240
+ "AB24 5RZ"
241
+ ]
242
+ self.assertEqual(
243
+ self.address.as_list(), address, "Incorrect Rule 6 w/ double building list format"
244
+ )
245
+
246
+ def test_string(self):
247
+ """Test conversion to a string"""
248
+ address = "91 OCEAN APARTMENTS, 52-54 PARK ROAD, ABERDEEN. AB24 5RZ"
249
+ self.assertEqual(
250
+ self.address.as_str(), address, "Incorrect Rule 6 w/ double building string format"
251
+ )
252
+
253
+ def test_tuple(self):
254
+ """Test conversion to a tuple"""
255
+ address = (
256
+ "91 OCEAN APARTMENTS",
257
+ "52-54 PARK ROAD",
258
+ "ABERDEEN",
259
+ "AB24 5RZ"
260
+ )
261
+ self.assertEqual(
262
+ self.address.as_tuple(), address, "Incorrect Rule 6 w/ double building tuple format"
263
+ )
264
+
265
+ def test_dict(self):
266
+ """Test conversion to a dict"""
267
+ address = {
268
+ 'line_1': "91 OCEAN APARTMENTS",
269
+ 'line_2': "52-54 PARK ROAD",
270
+ 'post_town': "ABERDEEN",
271
+ 'postcode': "AB24 5RZ"
272
+ }
273
+ self.assertEqual(
274
+ self.address.as_dict(), address, "Incorrect Rule 6 w/ double building dict format"
275
+ )
276
+
277
+ def test_premises(self):
278
+ """Test premises"""
279
+ premises = {
280
+ 'premises_number': 52,
281
+ 'premises_suffix': '-54',
282
+ 'premises_name': 'OCEAN APARTMENTS',
283
+ 'sub_premises_number': 91
284
+ }
285
+ self.assertEqual(
286
+ self.address.premises(), premises, "Incorrect Rule 6 w/ split building premises")
287
+
288
+
219
289
  class TestRule6(unittest.TestCase):
220
290
  """Test Address Rule 6 without Exception"""
221
291
 
@@ -1,26 +0,0 @@
1
- """Premises Extender Mixin"""
2
-
3
- import sys
4
- from .rule000 import Rule000 # pylint: disable=unused-import # noqa: F401
5
- from .rule001 import Rule001 # pylint: disable=unused-import # noqa: F401
6
- from .rule010 import Rule010 # pylint: disable=unused-import # noqa: F401
7
- from .rule100 import Rule100 # pylint: disable=unused-import # noqa: F401
8
- from .rule011 import Rule011 # pylint: disable=unused-import # noqa: F401
9
- from .rule101 import Rule101 # pylint: disable=unused-import # noqa: F401
10
- from .rule110 import Rule110 # pylint: disable=unused-import # noqa: F401
11
- from .rule111 import Rule111 # pylint: disable=unused-import # noqa: F401
12
-
13
-
14
- class ExtenderMixin():
15
- """Dynamic Premises processing"""
16
-
17
- @property
18
- def rule(self):
19
- """Returns premises rule class"""
20
- rule = ''.join(['0' if self.is_empty(k) else '1' for k in self.building_attrs])
21
- return getattr(sys.modules[__name__], 'Rule' + rule)
22
-
23
- def extend(self):
24
- """Dynamically extends instance with appropriate rule"""
25
- base_cls = self.__class__
26
- object.__setattr__(self, '__class__', type(base_cls.__name__, (base_cls, self.rule), {}))
@@ -1,3 +0,0 @@
1
- """Version"""
2
-
3
- __version__ = '1.0.0'
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