@@ -55,8 +55,42 @@ def setUp(self):
5555 theCleantxt = context .checkPythonCommand (clean_arguments , stderr = subprocess .STDOUT )
5656 self .assertIn (str ("running clean" ), str (theCleantxt ))
5757
58- def test_sdist_includes_required_files (self ):
59- """Test that the source distribution includes all required files."""
58+ def _get_package_version (self ):
59+ """
60+ Retrieve the current version of the package.
61+
62+ This helper method imports the package and extracts the __version__ attribute.
63+
64+ Returns:
65+ str: The version string of the package.
66+
67+ Raises:
68+ AssertionError: If the version string cannot be retrieved.
69+
70+ """
71+ try :
72+ from .context import multicast
73+ self .assertIsNotNone (multicast .__module__ )
74+ self .assertIsNotNone (multicast .__version__ )
75+ mcast_version = multicast .__version__
76+ self .assertEqual (type (mcast_version ), type (str ("" )), """Version is not a string.""" )
77+ return mcast_version
78+ except ImportError :
79+ self .fail ("""Failed to import the multicast package to retrieve version.""" )
80+
81+ def _build_sdist_and_get_members (self ):
82+ """Build the source distribution and return the list of member files and package version.
83+
84+ This helper method runs the command to create a source distribution (sdist) of the package
85+ and then extracts the list of files included in the archive.
86+
87+ Returns:
88+ tuple: A tuple containing the list of member file paths and the package version string.
89+
90+ Raises:
91+ AssertionError: If the build command does not run successfully or if no files are found
92+ in the 'dist' directory.
93+ """
6094 # Arguments need to build
6195 build_arguments = [
6296 str ("{} -m coverage run" ).format (_sys .executable ),
@@ -69,51 +103,60 @@ def test_sdist_includes_required_files(self):
69103 dist_files = sorted (_os .listdir (dist_dir ), reverse = True )
70104 self .assertTrue (len (dist_files ) > 0 , 'No files found in dist directory.' )
71105 sdist_path = _os .path .join (dist_dir , dist_files [0 ])
72- # Open the tar.gz file and inspect contents
106+ # Open the tar.gz file to inspect contents
73107 with tarfile .open (sdist_path , 'r:gz' ) as tar :
74108 members = tar .getnames ()
75- expected_files = [
76- 'multicast-1.5.0/README.md' ,
77- 'multicast-1.5.0/LICENSE.md' ,
78- 'multicast-1.5.0/requirements.txt' ,
79- 'multicast-1.5.0/setup.py' ,
80- 'multicast-1.5.0/MANIFEST.in' ,
81- # Include other important files and directories
82- ]
83- for expected_file in expected_files :
84- self .assertIn (
85- expected_file , members ,
86- str ('Missing {expected} in sdist.' ).format (expected = expected_file )
87- )
109+ version = self ._get_package_version ()
110+ return members , version
111+
112+ def test_sdist_includes_required_files (self ):
113+ """Test that the source distribution includes all required files.
114+
115+ This test verifies that the source distribution includes all expected files by building
116+ the sdist and checking if the required files are present in the tar archive.
117+ """
118+ members , version = self ._build_sdist_and_get_members ()
119+ package_prefix = str ("""multicast-{}""" ).format (version )
120+ expected_files = [
121+ str ("""{}/README.md""" ).format (package_prefix ),
122+ str ("""{}/LICENSE.md""" ).format (package_prefix ),
123+ str ("""{}/requirements.txt""" ).format (package_prefix ),
124+ str ("""{}/setup.py""" ).format (package_prefix ),
125+ str ("""{}/MANIFEST.in""" ).format (package_prefix ),
126+ str ("""{}/setup.cfg""" ).format (package_prefix ),
127+ str ("""{}/multicast/__init__.py""" ).format (package_prefix ),
128+ str ("""{}/multicast/__main__.py""" ).format (package_prefix ),
129+ str ("""{}/multicast/skt.py""" ).format (package_prefix ),
130+ str ("""{}/multicast/recv.py""" ).format (package_prefix ),
131+ str ("""{}/multicast/send.py""" ).format (package_prefix ),
132+ str ("""{}/multicast/hear.py""" ).format (package_prefix ),
133+ # Include other important files and directories
134+ ]
135+ for expected_file in expected_files :
136+ self .assertIn (
137+ expected_file , members ,
138+ str ("""Missing {expected} in sdist.""" ).format (expected = expected_file )
139+ )
88140
89141 def test_sdist_excludes_unwanted_files (self ):
90- """Test that the source distribution excludes unwanted files."""
91- # Arguments need to build
92- build_arguments = [
93- str ("{} -m coverage run" ).format (_sys .executable ),
94- 'setup.py' , 'sdist' , '--formats=gztar'
142+ """Test that the source distribution excludes unwanted files.
143+
144+ This test ensures that unwanted files and directories are not included in the source distribution
145+ by building the sdist and verifying that these files are absent from the tar archive.
146+ """
147+ members , version = self ._build_sdist_and_get_members ()
148+ package_prefix = str ("""multicast-{}""" ).format (version )
149+ unwanted_files = [
150+ str ("""{}/.gitignore""" ).format (package_prefix ),
151+ str ("""{}/.github/""" ).format (package_prefix ),
152+ str ("""{}/tests/""" ).format (package_prefix ),
153+ # Exclude other files or directories as specified in MANIFEST.in
95154 ]
96- # Build the source distribution
97- theBuildtxt = context .checkPythonCommand (build_arguments , stderr = subprocess .STDOUT )
98- self .assertIn (str ("running sdist" ), str (theBuildtxt ))
99- dist_dir = _os .path .join (_os .getcwd (), 'dist' )
100- dist_files = _os .listdir (dist_dir )
101- dist_files = sorted (_os .listdir (dist_dir ), reverse = True )
102- sdist_path = _os .path .join (dist_dir , dist_files [0 ])
103- # Open the tar.gz file and inspect contents
104- with tarfile .open (sdist_path , 'r:gz' ) as tar :
105- members = tar .getnames ()
106- unwanted_files = [
107- 'multicast-1.5.0/.gitignore' ,
108- 'multicast-1.5.0/.github/' ,
109- 'multicast-1.5.0/tests/' ,
110- # Exclude other files or directories as specified in MANIFEST.in
111- ]
112- for unwanted_file in unwanted_files :
113- self .assertNotIn (
114- unwanted_file , members ,
115- str ('Unwanted file {reject} found in sdist.' ).format (reject = unwanted_file )
116- )
155+ for unwanted_file in unwanted_files :
156+ self .assertNotIn (
157+ unwanted_file , members ,
158+ str ("""Unwanted file {reject} found in sdist.""" ).format (reject = unwanted_file )
159+ )
117160
118161
119162# leave this part
0 commit comments