From 4591374ad2d4552b8ca5be321cdc33e388f64c8e Mon Sep 17 00:00:00 2001 From: codeperfectplus Date: Sat, 7 Jun 2025 18:06:00 +0530 Subject: [PATCH 1/3] Bump version to 3.0.6 and update changelog with minor release details --- CHANGELOG.md | 6 ++++++ docs/conf.py | 2 +- random_profile/__about__.py | 2 +- setup.py | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f81d1a5..960c1cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format ## Changelog + +## [V3.0.5] - Minor Release - 07-06-2025 + +- [x] Bug fixes +- [x] Updated documentation + ## [V3.0.5] - Minor Release - 02-01-2025 - [x] Bug fixes diff --git a/docs/conf.py b/docs/conf.py index 1875dbf..e5ca515 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,7 +5,7 @@ __title__ = 'RandomProfileGenerator' __package_name__ = 'random_profile' -__version__ = '3.0.5' +__version__ = '3.0.6' __description__ = "Python Module To Generate Random Profile Data" __email__ = "deepak008@live.com" __author__ = 'Deepak Raj' diff --git a/random_profile/__about__.py b/random_profile/__about__.py index 67064c7..8637764 100644 --- a/random_profile/__about__.py +++ b/random_profile/__about__.py @@ -1,6 +1,6 @@ __title__ = 'RandomProfileGenerator' __package_name__ = 'random_profile' -__version__ = '3.0.5' +__version__ = '3.0.6' __description__ = "Python Module To Generate Random Profile Data" __email__ = "deepak008@live.com" __author__ = 'Deepak Raj' diff --git a/setup.py b/setup.py index eb41f55..3ec58b8 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ __title__ = 'RandomProfileGenerator' __package_name__ = 'random_profile' -__version__ = '3.0.5' +__version__ = '3.0.6' __description__ = "Python Module To Generate Random Profile Data" __email__ = "deepak008@live.com" __author__ = 'Deepak Raj' From 34249b4e1ae6476d5d65598c432bbfbb58e486fd Mon Sep 17 00:00:00 2001 From: codeperfectplus Date: Sat, 7 Jun 2025 18:32:09 +0530 Subject: [PATCH 2/3] Refactor profile generation to use dataclass for improved structure and readability; update tests to reflect changes in return types --- random_profile/main.py | 117 ++++++++++++++++++++++++++++++----------- tests/test_cases.py | 16 +++--- 2 files changed, 94 insertions(+), 39 deletions(-) diff --git a/random_profile/main.py b/random_profile/main.py index 809ec48..59590c1 100644 --- a/random_profile/main.py +++ b/random_profile/main.py @@ -10,10 +10,13 @@ import uuid import random from typing import List, Tuple +from dataclasses import dataclass, asdict + # Ensure the current directory is in the path to import local modules # Adjust your path as needed sys.path.append('.') +from random_profile.enums import gender from random_profile.enums.gender import Gender from random_profile import utils from random_profile.__about__ import __version__ @@ -42,6 +45,30 @@ job_titles = utils.load_txt_file(job_titles_txt) job_levels = utils.load_txt_file(job_levels_txt) +@dataclass +class Profile: + id: str + gender: str + first_name: str + last_name: str + full_name: str + hair_color: str + blood_type: str + job_title: str + dob: str + age: int + phone_number: str + email: str + height: int + weight: int + ip_address: str + address: dict + full_address: str + job_experience: str + mother: str + father: str + payment_card: dict + coordinates: str class RandomProfile: """ @@ -95,6 +122,9 @@ def __getitem__(self, index): profiles = self.full_profiles() return profiles[index] + def _resolve_count(self, num): + return self.num if num is None else num + def ip_address(self, num: int = None) -> List[str]: """Generate one or more IPv4 addresses.""" count = self.num if num is None else num @@ -107,21 +137,21 @@ def job_title(self, num: int = None) -> List[str]: count = self.num if num is None else num if count == 1: return [random.choice(job_titles)] - return random.choices(job_titles, k=count) + return random.choices(job_titles, k=self._resolve_count(num)) def blood_type(self, num: int = None) -> List[str]: """Generate one or more blood types.""" count = self.num if num is None else num if count == 1: return [random.choice(blood_types)] - return random.choices(blood_types, k=count) + return random.choices(blood_types, k=self._resolve_count(num)) def hair_color(self, num: int = None) -> List[str]: """Generate one or more hair colors.""" count = self.num if num is None else num if count == 1: return [random.choice(hair_colors)] - return random.choices(hair_colors, k=count) + return random.choices(hair_colors, k=self._resolve_count(num)) def dob_age(self, num: int = None) -> List[Tuple[str, int]]: """Generate DOB and age tuples.""" @@ -175,14 +205,14 @@ def first_names(self, num: int = None, gender: Gender = None) -> List[str]: if count == 1: return [random.choice(names_pool)] - return random.choices(names_pool, k=count) + return random.choices(names_pool, k=self._resolve_count(num)) def last_names(self, num: int = None) -> List[str]: """Generate one or more last names.""" count = self.num if num is None else num if count == 1: return [random.choice(lname)] - return random.choices(lname, k=count) + return random.choices(lname, k=self._resolve_count(num)) def full_names(self, num: int = None, gender: Gender = None) -> List[str]: """Generate one or more full names (first + last).""" @@ -251,31 +281,56 @@ def full_profiles(self, num: int = None, gender: Gender = None) -> List[dict]: card = utils.generate_random_card() # Compose the profile dict - profile = { - 'id': str(uuid.uuid4()), - 'gender': this_gender.value, - 'first_name': f_name, - 'last_name': l_name, - 'full_name': full_name, - 'hair_color': [hair], # matching the list return type from hair_color() - 'blood_type': [blood], # matching the list return type from blood_type() - 'job_title': [random.choice(job_titles)], - 'dob': dob, - 'age': age, - 'phone_number': phone_number, - 'email': f"{f_name.lower()}{l_name.lower()}@example.com", - 'height': height, - 'weight': weight, - 'ip_address': [utils.ipv4_gen()], # typically returns a list - 'address': address_dict, - 'full_address': full_address, - 'job_experience': job_experience, - 'mother': mother, - 'father': father, - 'payment_card': card, - 'coordinates': coords_pretty - } - - profile_list.append(profile) + # profile = { + # 'id': str(uuid.uuid4()), + # 'gender': this_gender.value, + # 'first_name': f_name, + # 'last_name': l_name, + # 'full_name': full_name, + # 'hair_color': hair, # matching the list return type from hair_color() + # 'blood_type': blood, # matching the list return type from blood_type() + # 'job_title': random.choice(job_titles), + # 'dob': dob, + # 'age': age, + # 'phone_number': phone_number, + # 'email': f"{f_name.lower()}{l_name.lower()}@example.com", + # 'height': height, + # 'weight': weight, + # 'ip_address': utils.ipv4_gen(), # typically returns a list + # 'address': address_dict, + # 'full_address': full_address, + # 'job_experience': job_experience, + # 'mother': mother, + # 'father': father, + # 'payment_card': card, + # 'coordinates': coords_pretty + # } + + # profile_list.append(profile) + profile = Profile( + id=str(uuid.uuid4()), + gender=this_gender.value if this_gender.value is not None else "", + first_name=f_name, + last_name=l_name, + full_name=full_name, + hair_color=hair, + blood_type=blood, + job_title=random.choice(job_titles), + dob=dob, + age=age, + phone_number=phone_number, + email=f"{f_name.lower()}{l_name.lower()}@example.com", + height=height, + weight=weight, + ip_address=utils.ipv4_gen(), + address=address_dict, + full_address=full_address, + job_experience=job_experience, + mother=mother, + father=father, + payment_card=card, + coordinates=coords_pretty + ) + profile_list.append(asdict(profile)) return profile_list diff --git a/tests/test_cases.py b/tests/test_cases.py index f46ff15..776468b 100644 --- a/tests/test_cases.py +++ b/tests/test_cases.py @@ -14,7 +14,7 @@ class RandomProfileTest(unittest.TestCase): # ----------------------------------------------------------------- # def test_fname_instance(self): - self.assertIsInstance(random_profile.first_names(), str) + self.assertIsInstance(random_profile.first_names(), List) def test_faname_with_num(self): self.assertEqual(len(RandomProfile(num=10).first_names()), 10) @@ -24,7 +24,7 @@ def test_fname_with_num_instance(self): # ----------------------------------------------------------------- # def test_lname_instance(self): - self.assertIsInstance(random_profile.last_names(), str) + self.assertIsInstance(random_profile.last_names(), List) def test_lname_with_num(self): self.assertEqual(len(RandomProfile(num=10).last_names()), 10) @@ -34,7 +34,7 @@ def test_lname_with_num_instance(self): # ----------------------------------------------------------------- # def test_full_names_instance(self): - self.assertIsInstance(random_profile.full_names(), str) + self.assertIsInstance(random_profile.full_names(), List) def test_full_names_with_num(self): self.assertEqual(len(RandomProfile(num=10).full_names()), 10) @@ -54,7 +54,7 @@ def test_full_profiles_with_num_instance(self): # ----------------------------------------------------------------- # def test_ipv4_instance(self): - self.assertIsInstance(random_profile.ip_address(), str) + self.assertIsInstance(random_profile.ip_address(), List) def test_ipv4_with_num(self): self.assertEqual(len(RandomProfile(num=10).ip_address()), 10) @@ -64,7 +64,7 @@ def test_ipv4_with_num_instance(self): # ----------------------------------------------------------------- # def test_job_title_instance(self): - self.assertIsInstance(random_profile.job_title(), str) + self.assertIsInstance(random_profile.job_title(), List) def test_job_title_with_num(self): self.assertEqual(len(RandomProfile(num=10).job_title()), 10) @@ -74,7 +74,7 @@ def test_job_title_with_num_instance(self): # ----------------------------------------------------------------- # def test_blood_type_instance(self): - self.assertIsInstance(random_profile.blood_type(), str) + self.assertIsInstance(random_profile.blood_type(), List) def test_blood_type_with_num(self): self.assertEqual(len(RandomProfile(num=10).blood_type()), 10) @@ -84,7 +84,7 @@ def test_blood_type_with_num_instance(self): # ----------------------------------------------------------------- # def test_hair_color_instance(self): - self.assertIsInstance(random_profile.hair_color(), str) + self.assertIsInstance(random_profile.hair_color(), List) def test_hair_color_with_num(self): self.assertEqual(len(RandomProfile(num=10).hair_color()), 10) @@ -94,7 +94,7 @@ def test_hair_color_with_num_instance(self): # ----------------------------------------------------------------- # def test_dob_age_instance(self): - self.assertIsInstance(random_profile.dob_age(), Tuple) + self.assertIsInstance(random_profile.dob_age(), List) def test_dob_age_with_num(self): self.assertEqual(len(RandomProfile(num=10).dob_age()), 10) From 9ec1f0f9c0589e47f4b8bccfedb7e982957126c6 Mon Sep 17 00:00:00 2001 From: codeperfectplus Date: Sat, 7 Jun 2025 18:33:16 +0530 Subject: [PATCH 3/3] Update changelog for version 3.0.6 with recent changes and improvements --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 960c1cc..c1a7d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Changelog - - -## [V3.0.5] - Minor Release - 07-06-2025 +## [V3.0.6] - Minor Release - 07-06-2025 - [x] Bug fixes - [x] Updated documentation +- [x] Refactored profile generation to use dataclass for improved structure and readability +- [x] Updated tests to reflect changes in return types +- [x] Bump version to 3.0.6 ## [V3.0.5] - Minor Release - 02-01-2025