def test_get_package(self): package_a = MyPackage(self.TMP_DIR, "packagea") SetupCfg(package_a.full_name).write(package_a.package_dir) with chdir(self.TMP_DIR): Package(package_name=package_a.full_name) Package(package_dir=package_a.package_dir)
def test_resolve_circular_dependencies(self): package_b = MyPackage(self.TMP_DIR, "packageb") package_a = MyPackage(self.TMP_DIR, "packagea") SetupCfg(package_a.full_name, dependencies=[package_b.full_name ]).write(package_a.package_dir) SetupCfg(package_b.full_name, dependencies=[package_a.full_name ]).write(package_b.package_dir) with chdir(self.TMP_DIR): with self.assertRaises(SystemExit) as err: Package(package_name=package_a.full_name).get_dependents( package_a.package_dir) self.assertTrue( "Circular dependency detected!" in err.exception.args[0])
def test_get_configs(self): package_a = MyPackage(self.TMP_DIR, "packagea") with chdir(self.TMP_DIR): os.mkdir(package_a.name) SetupCfg(package_a.full_name).write(package_a.package_dir) self.assertIsInstance(MockPackage().get_cfg(package_a.package_dir), configparser.ConfigParser)
def setUp(cls): super(TestPackages, cls).setUp() # Create a fake package that's available to test. with chdir(cls.TMP_DIR): package_a = MyPackage(d=cls.TMP_DIR, name="packagea") os.mkdir(package_a.name) SetupCfg(package_a.full_name).write(package_a.package_dir) subprocess.call(["git", "add", "."])
def test_get_package_doesnt_exist(self): """Test both ways to initialize """ package_a = MyPackage(self.TMP_DIR, "packagea") with chdir(self.TMP_DIR): with self.assertRaises(PackageDoesNotExistException): Package(package_name=package_a.full_name).get_dependents( package_a.package_dir) with self.assertRaises(PackageDoesNotExistException): Package(package_dir=package_a.package_dir).get_dependents( package_a.package_dir)
def test_resolve_dependencies_depends_on_itself(self): package_a = MyPackage(self.TMP_DIR, "packagea") SetupCfg(package_a.full_name, dependencies=[package_a.full_name ]).write(package_a.package_dir) with chdir(self.TMP_DIR): with self.assertRaises(SystemExit) as err: Package(package_name=package_a.full_name).get_dependents( package_a.package_dir) self.assertTrue('is dependent on itself' in err.exception.args[0])
def test_resolve_dependencies(self): package_c = MyPackage(self.TMP_DIR, "packagec") package_b = MyPackage(self.TMP_DIR, "packageb") package_a = MyPackage(self.TMP_DIR, "packagea") SetupCfg(package_a.full_name, dependencies=[package_b.full_name, package_c.full_name ]).write(package_a.package_dir) SetupCfg(package_b.full_name, dependencies=[package_c.full_name ]).write(package_b.package_dir) SetupCfg(package_c.full_name).write(package_c.package_dir) with chdir(self.TMP_DIR): a_dependencies = Package( package_name=package_a.full_name).get_dependents( package_a.package_dir) self.assertEqual(a_dependencies[0].package_name, "company_packageb") self.assertEqual(a_dependencies[1].package_name, "company_packagec")
def test_changed_files(self): expected_changes = [['A', 'packagea/setup.cfg']] with chdir(self.TMP_DIR): package_a = MyPackage(d=self.TMP_DIR, name="packagea") os.mkdir(package_a.name) SetupCfg(package_a.full_name).write(package_a.package_dir) subprocess.call(["git", "add", "."]) parent_branch = detect_changed_packages.get_parent_branch() changed_files = detect_changed_packages.get_changed_files( parent_branch) self.assertEqual(changed_files, expected_changes, parent_branch)
def test_changed_packages(self): input_changes = [["A", "packagea/module.py"]] expected_changes = "company_packagea" with chdir(self.TMP_DIR): package_a = MyPackage(d=self.TMP_DIR, name="packagea") os.mkdir(package_a.name) SetupCfg(package_a.full_name).write(package_a.package_dir) subprocess.call(["git", "add", "."]) changed_packages = detect_changed_packages.get_unique_changed_packages( input_changes) changed_package = list(changed_packages.keys())[0] self.assertEqual(changed_package, expected_changes)