Skip to content

Commit

Permalink
Use a SiteBuilder class to build files in the site, traversing the cl…
Browse files Browse the repository at this point in the history
…ass hierarchy explicitly and avoiding the need for separate setUp calls for each.
  • Loading branch information
jaraco committed Dec 3, 2023
1 parent 7238302 commit e886c99
Showing 1 changed file with 18 additions and 44 deletions.
62 changes: 18 additions & 44 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ def setUp(self):
self.fixtures.enter_context(self.add_sys_path(self.site_dir))


class DistInfoPkg(OnSysPath, SiteDir):
class SiteBuilder(SiteDir):
def setUp(self):
super().setUp()
for cls in self.__class__.mro():
with contextlib.suppress(AttributeError):
build_files(cls.files, prefix=self.site_dir)


class DistInfoPkg(OnSysPath, SiteBuilder):
files: FilesSpec = {
"distinfo_pkg-1.0.0.dist-info": {
"METADATA": """
Expand All @@ -112,10 +120,6 @@ def main():
""",
}

def setUp(self):
super().setUp()
build_files(DistInfoPkg.files, self.site_dir)

def make_uppercase(self):
"""
Rewrite metadata with everything uppercase.
Expand All @@ -127,7 +131,7 @@ def make_uppercase(self):
build_files(files, self.site_dir)


class DistInfoPkgWithDot(OnSysPath, SiteDir):
class DistInfoPkgWithDot(OnSysPath, SiteBuilder):
files: FilesSpec = {
"pkg_dot-1.0.0.dist-info": {
"METADATA": """
Expand All @@ -137,12 +141,8 @@ class DistInfoPkgWithDot(OnSysPath, SiteDir):
},
}

def setUp(self):
super().setUp()
build_files(DistInfoPkgWithDot.files, self.site_dir)


class DistInfoPkgWithDotLegacy(OnSysPath, SiteDir):
class DistInfoPkgWithDotLegacy(OnSysPath, SiteBuilder):
files: FilesSpec = {
"pkg.dot-1.0.0.dist-info": {
"METADATA": """
Expand All @@ -158,18 +158,12 @@ class DistInfoPkgWithDotLegacy(OnSysPath, SiteDir):
},
}

def setUp(self):
super().setUp()
build_files(DistInfoPkgWithDotLegacy.files, self.site_dir)


class DistInfoPkgOffPath(SiteDir):
def setUp(self):
super().setUp()
build_files(DistInfoPkg.files, self.site_dir)
class DistInfoPkgOffPath(SiteBuilder):
files = DistInfoPkg.files


class EggInfoPkg(OnSysPath, SiteDir):
class EggInfoPkg(OnSysPath, SiteBuilder):
files: FilesSpec = {
"egginfo_pkg.egg-info": {
"PKG-INFO": """
Expand Down Expand Up @@ -204,12 +198,8 @@ def main():
""",
}

def setUp(self):
super().setUp()
build_files(EggInfoPkg.files, prefix=self.site_dir)


class EggInfoPkgPipInstalledNoToplevel(OnSysPath, SiteDir):
class EggInfoPkgPipInstalledNoToplevel(OnSysPath, SiteBuilder):
files: FilesSpec = {
"egg_with_module_pkg.egg-info": {
"PKG-INFO": "Name: egg_with_module-pkg",
Expand Down Expand Up @@ -239,12 +229,8 @@ def main():
""",
}

def setUp(self):
super().setUp()
build_files(EggInfoPkgPipInstalledNoToplevel.files, prefix=self.site_dir)


class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteDir):
class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteBuilder):
files: FilesSpec = {
"egg_with_no_modules_pkg.egg-info": {
"PKG-INFO": "Name: egg_with_no_modules-pkg",
Expand All @@ -269,12 +255,8 @@ class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteDir):
},
}

def setUp(self):
super().setUp()
build_files(EggInfoPkgPipInstalledNoModules.files, prefix=self.site_dir)


class EggInfoPkgSourcesFallback(OnSysPath, SiteDir):
class EggInfoPkgSourcesFallback(OnSysPath, SiteBuilder):
files: FilesSpec = {
"sources_fallback_pkg.egg-info": {
"PKG-INFO": "Name: sources_fallback-pkg",
Expand All @@ -295,12 +277,8 @@ def main():
""",
}

def setUp(self):
super().setUp()
build_files(EggInfoPkgSourcesFallback.files, prefix=self.site_dir)


class EggInfoFile(OnSysPath, SiteDir):
class EggInfoFile(OnSysPath, SiteBuilder):
files: FilesSpec = {
"egginfo_file.egg-info": """
Metadata-Version: 1.0
Expand All @@ -316,10 +294,6 @@ class EggInfoFile(OnSysPath, SiteDir):
""",
}

def setUp(self):
super().setUp()
build_files(EggInfoFile.files, prefix=self.site_dir)


# dedent all text strings before writing
orig = _path.create.registry[str]
Expand Down

0 comments on commit e886c99

Please sign in to comment.