Skip to content

Commit fe254e3

Browse files
πŸ”– Release v3.0.6 – Refactor, Version Bump & Changelog Update (#63)
* Bump version to 3.0.6 and update changelog with minor release details * Refactor profile generation to use dataclass for improved structure and readability; update tests to reflect changes in return types * Update changelog for version 3.0.6 with recent changes and improvements
1 parent c73edd0 commit fe254e3

File tree

6 files changed

+104
-43
lines changed

6 files changed

+104
-43
lines changed

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
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).
44

5-
## Changelog
5+
## [V3.0.6] - Minor Release - 07-06-2025
6+
7+
- [x] Bug fixes
8+
- [x] Updated documentation
9+
- [x] Refactored profile generation to use dataclass for improved structure and readability
10+
- [x] Updated tests to reflect changes in return types
11+
- [x] Bump version to 3.0.6
612

713
## [V3.0.5] - Minor Release - 02-01-2025
814

β€Ždocs/conf.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
__title__ = 'RandomProfileGenerator'
77
__package_name__ = 'random_profile'
8-
__version__ = '3.0.5'
8+
__version__ = '3.0.6'
99
__description__ = "Python Module To Generate Random Profile Data"
1010
__email__ = "[email protected]"
1111
__author__ = 'Deepak Raj'

β€Žrandom_profile/__about__.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'RandomProfileGenerator'
22
__package_name__ = 'random_profile'
3-
__version__ = '3.0.5'
3+
__version__ = '3.0.6'
44
__description__ = "Python Module To Generate Random Profile Data"
55
__email__ = "[email protected]"
66
__author__ = 'Deepak Raj'

β€Žrandom_profile/main.pyβ€Ž

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import uuid
1111
import random
1212
from typing import List, Tuple
13+
from dataclasses import dataclass, asdict
1314

15+
# Ensure the current directory is in the path to import local modules
1416
# Adjust your path as needed
1517
sys.path.append('.')
1618

19+
from random_profile.enums import gender
1720
from random_profile.enums.gender import Gender
1821
from random_profile import utils
1922
from random_profile.__about__ import __version__
@@ -42,6 +45,30 @@
4245
job_titles = utils.load_txt_file(job_titles_txt)
4346
job_levels = utils.load_txt_file(job_levels_txt)
4447

48+
@dataclass
49+
class Profile:
50+
id: str
51+
gender: str
52+
first_name: str
53+
last_name: str
54+
full_name: str
55+
hair_color: str
56+
blood_type: str
57+
job_title: str
58+
dob: str
59+
age: int
60+
phone_number: str
61+
email: str
62+
height: int
63+
weight: int
64+
ip_address: str
65+
address: dict
66+
full_address: str
67+
job_experience: str
68+
mother: str
69+
father: str
70+
payment_card: dict
71+
coordinates: str
4572

4673
class RandomProfile:
4774
"""
@@ -95,6 +122,9 @@ def __getitem__(self, index):
95122
profiles = self.full_profiles()
96123
return profiles[index]
97124

125+
def _resolve_count(self, num):
126+
return self.num if num is None else num
127+
98128
def ip_address(self, num: int = None) -> List[str]:
99129
"""Generate one or more IPv4 addresses."""
100130
count = self.num if num is None else num
@@ -107,21 +137,21 @@ def job_title(self, num: int = None) -> List[str]:
107137
count = self.num if num is None else num
108138
if count == 1:
109139
return [random.choice(job_titles)]
110-
return random.choices(job_titles, k=count)
140+
return random.choices(job_titles, k=self._resolve_count(num))
111141

112142
def blood_type(self, num: int = None) -> List[str]:
113143
"""Generate one or more blood types."""
114144
count = self.num if num is None else num
115145
if count == 1:
116146
return [random.choice(blood_types)]
117-
return random.choices(blood_types, k=count)
147+
return random.choices(blood_types, k=self._resolve_count(num))
118148

119149
def hair_color(self, num: int = None) -> List[str]:
120150
"""Generate one or more hair colors."""
121151
count = self.num if num is None else num
122152
if count == 1:
123153
return [random.choice(hair_colors)]
124-
return random.choices(hair_colors, k=count)
154+
return random.choices(hair_colors, k=self._resolve_count(num))
125155

126156
def dob_age(self, num: int = None) -> List[Tuple[str, int]]:
127157
"""Generate DOB and age tuples."""
@@ -175,14 +205,14 @@ def first_names(self, num: int = None, gender: Gender = None) -> List[str]:
175205

176206
if count == 1:
177207
return [random.choice(names_pool)]
178-
return random.choices(names_pool, k=count)
208+
return random.choices(names_pool, k=self._resolve_count(num))
179209

180210
def last_names(self, num: int = None) -> List[str]:
181211
"""Generate one or more last names."""
182212
count = self.num if num is None else num
183213
if count == 1:
184214
return [random.choice(lname)]
185-
return random.choices(lname, k=count)
215+
return random.choices(lname, k=self._resolve_count(num))
186216

187217
def full_names(self, num: int = None, gender: Gender = None) -> List[str]:
188218
"""Generate one or more full names (first + last)."""
@@ -251,31 +281,56 @@ def full_profiles(self, num: int = None, gender: Gender = None) -> List[dict]:
251281
card = utils.generate_random_card()
252282

253283
# Compose the profile dict
254-
profile = {
255-
'id': str(uuid.uuid4()),
256-
'gender': this_gender.value,
257-
'first_name': f_name,
258-
'last_name': l_name,
259-
'full_name': full_name,
260-
'hair_color': [hair], # matching the list return type from hair_color()
261-
'blood_type': [blood], # matching the list return type from blood_type()
262-
'job_title': [random.choice(job_titles)],
263-
'dob': dob,
264-
'age': age,
265-
'phone_number': phone_number,
266-
'email': f"{f_name.lower()}{l_name.lower()}@example.com",
267-
'height': height,
268-
'weight': weight,
269-
'ip_address': [utils.ipv4_gen()], # typically returns a list
270-
'address': address_dict,
271-
'full_address': full_address,
272-
'job_experience': job_experience,
273-
'mother': mother,
274-
'father': father,
275-
'payment_card': card,
276-
'coordinates': coords_pretty
277-
}
278-
279-
profile_list.append(profile)
284+
# profile = {
285+
# 'id': str(uuid.uuid4()),
286+
# 'gender': this_gender.value,
287+
# 'first_name': f_name,
288+
# 'last_name': l_name,
289+
# 'full_name': full_name,
290+
# 'hair_color': hair, # matching the list return type from hair_color()
291+
# 'blood_type': blood, # matching the list return type from blood_type()
292+
# 'job_title': random.choice(job_titles),
293+
# 'dob': dob,
294+
# 'age': age,
295+
# 'phone_number': phone_number,
296+
# 'email': f"{f_name.lower()}{l_name.lower()}@example.com",
297+
# 'height': height,
298+
# 'weight': weight,
299+
# 'ip_address': utils.ipv4_gen(), # typically returns a list
300+
# 'address': address_dict,
301+
# 'full_address': full_address,
302+
# 'job_experience': job_experience,
303+
# 'mother': mother,
304+
# 'father': father,
305+
# 'payment_card': card,
306+
# 'coordinates': coords_pretty
307+
# }
308+
309+
# profile_list.append(profile)
310+
profile = Profile(
311+
id=str(uuid.uuid4()),
312+
gender=this_gender.value if this_gender.value is not None else "",
313+
first_name=f_name,
314+
last_name=l_name,
315+
full_name=full_name,
316+
hair_color=hair,
317+
blood_type=blood,
318+
job_title=random.choice(job_titles),
319+
dob=dob,
320+
age=age,
321+
phone_number=phone_number,
322+
email=f"{f_name.lower()}{l_name.lower()}@example.com",
323+
height=height,
324+
weight=weight,
325+
ip_address=utils.ipv4_gen(),
326+
address=address_dict,
327+
full_address=full_address,
328+
job_experience=job_experience,
329+
mother=mother,
330+
father=father,
331+
payment_card=card,
332+
coordinates=coords_pretty
333+
)
334+
profile_list.append(asdict(profile))
280335

281336
return profile_list

β€Žsetup.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
__title__ = 'RandomProfileGenerator'
1111
__package_name__ = 'random_profile'
12-
__version__ = '3.0.5'
12+
__version__ = '3.0.6'
1313
__description__ = "Python Module To Generate Random Profile Data"
1414
__email__ = "[email protected]"
1515
__author__ = 'Deepak Raj'

β€Žtests/test_cases.pyβ€Ž

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class RandomProfileTest(unittest.TestCase):
1515
# ----------------------------------------------------------------- #
1616
def test_fname_instance(self):
17-
self.assertIsInstance(random_profile.first_names(), str)
17+
self.assertIsInstance(random_profile.first_names(), List)
1818

1919
def test_faname_with_num(self):
2020
self.assertEqual(len(RandomProfile(num=10).first_names()), 10)
@@ -24,7 +24,7 @@ def test_fname_with_num_instance(self):
2424

2525
# ----------------------------------------------------------------- #
2626
def test_lname_instance(self):
27-
self.assertIsInstance(random_profile.last_names(), str)
27+
self.assertIsInstance(random_profile.last_names(), List)
2828

2929
def test_lname_with_num(self):
3030
self.assertEqual(len(RandomProfile(num=10).last_names()), 10)
@@ -34,7 +34,7 @@ def test_lname_with_num_instance(self):
3434

3535
# ----------------------------------------------------------------- #
3636
def test_full_names_instance(self):
37-
self.assertIsInstance(random_profile.full_names(), str)
37+
self.assertIsInstance(random_profile.full_names(), List)
3838

3939
def test_full_names_with_num(self):
4040
self.assertEqual(len(RandomProfile(num=10).full_names()), 10)
@@ -54,7 +54,7 @@ def test_full_profiles_with_num_instance(self):
5454

5555
# ----------------------------------------------------------------- #
5656
def test_ipv4_instance(self):
57-
self.assertIsInstance(random_profile.ip_address(), str)
57+
self.assertIsInstance(random_profile.ip_address(), List)
5858

5959
def test_ipv4_with_num(self):
6060
self.assertEqual(len(RandomProfile(num=10).ip_address()), 10)
@@ -64,7 +64,7 @@ def test_ipv4_with_num_instance(self):
6464

6565
# ----------------------------------------------------------------- #
6666
def test_job_title_instance(self):
67-
self.assertIsInstance(random_profile.job_title(), str)
67+
self.assertIsInstance(random_profile.job_title(), List)
6868

6969
def test_job_title_with_num(self):
7070
self.assertEqual(len(RandomProfile(num=10).job_title()), 10)
@@ -74,7 +74,7 @@ def test_job_title_with_num_instance(self):
7474

7575
# ----------------------------------------------------------------- #
7676
def test_blood_type_instance(self):
77-
self.assertIsInstance(random_profile.blood_type(), str)
77+
self.assertIsInstance(random_profile.blood_type(), List)
7878

7979
def test_blood_type_with_num(self):
8080
self.assertEqual(len(RandomProfile(num=10).blood_type()), 10)
@@ -84,7 +84,7 @@ def test_blood_type_with_num_instance(self):
8484

8585
# ----------------------------------------------------------------- #
8686
def test_hair_color_instance(self):
87-
self.assertIsInstance(random_profile.hair_color(), str)
87+
self.assertIsInstance(random_profile.hair_color(), List)
8888

8989
def test_hair_color_with_num(self):
9090
self.assertEqual(len(RandomProfile(num=10).hair_color()), 10)
@@ -94,7 +94,7 @@ def test_hair_color_with_num_instance(self):
9494

9595
# ----------------------------------------------------------------- #
9696
def test_dob_age_instance(self):
97-
self.assertIsInstance(random_profile.dob_age(), Tuple)
97+
self.assertIsInstance(random_profile.dob_age(), List)
9898

9999
def test_dob_age_with_num(self):
100100
self.assertEqual(len(RandomProfile(num=10).dob_age()), 10)

0 commit comments

Comments
Β (0)