def test_graph_should_produce_minimal_setting_dependency_set_by_name(): mdl = MockDependencyLoader() mdl.a_setting("test") g = Setup(mdl) g.add_setting("test") g.add_setting("test") assert g.settings == [Setting("test")]
def test_graph_should_be_able_to_load_feature_with_import_dependencies(): mdl = MockDependencyLoader() mdl.a_feature("test", ["from setuptools import setup"]) g = Setup(mdl) g.add_feature("test") assert g.imports == {"from setuptools import setup"} assert g.features == {Feature("test")}
def test_graph_should_import_setting_with_import_dependencies(): mdl = MockDependencyLoader() mdl.a_setting("test", imports=["from setuptools import setup"]) g = Setup(mdl) g.add_setting("test") assert g.imports == {"from setuptools import setup"} assert g.settings == [Setting("test")]
def test_adding_cyclical_feature_dependencies_is_fine(): mdl = MockDependencyLoader() mdl.a_feature("test", features=["test2"]) mdl.a_feature("test2", features=["test3"]) mdl.a_feature("test3", features=["test"]) g = Setup(mdl) g.add_feature("test") assert g.features == {Feature("test"), Feature("test2"), Feature("test3")}
def test_graph_should_import_feature_with_feature_dependencies(): mdl = MockDependencyLoader() mdl.a_feature("test", features=["test2"]) mdl.a_feature("test2", imports=["from setuptools import setup"]) g = Setup(mdl) g.add_feature("test") assert g.imports == {"from setuptools import setup"} assert g.features == {Feature("test"), Feature("test2")}
def setupy( imports=None, features=None, settings=None, literal_settings=None, dependency_loader=None, feature_path=None, settings_path=None, include_help=False): if dependency_loader is None: feature_path = (feature_path or os.environ.get("SETUPY_FEATURES") or os.path.join(DIR_PATH, "features")) settings_path = (settings_path or os.environ.get("SETUPY_SETTINGS") or os.path.join(DIR_PATH, "settings")) dependency_loader = FileDependencyLoader(feature_path, settings_path) setup = Setup(dependency_loader) if (not features): features = [] if (not imports): imports = [] if (not settings): settings = [] for i in imports: setup.add_import(i) for f in features: try: setup.add_feature(f) except FeatureNotFoundError: print(f'WARNING: Feature {f} was not found', file=sys.stderr) for s in settings: try: setup.add_setting(s) except SettingNotFoundError: print(f'WARNING: Setting {s} was not found', file=sys.stderr) literal_loader = YamlDependencyLoader() for s in literal_settings or []: setup.add_setting_object(literal_loader.load_setting(s)) return serialize(setup, include_help)
def test_serializer_can_serialize_with_imports(): setup = Setup(MockDependencyLoader()) setup.add_import("from setuptools import setup") setup.add_import("from setuptools import find_packages") setup.add_import("from os import path") setup.add_import("from io import open") assert serialize_imports(setup) == """from io import open
def test_serializer_can_serialize_settings(): mdl = MockDependencyLoader() mdl.a_setting('BASE', properties={ "name": "\"setupy\"", "version": "\"0.1.0\"", "packages": "find_packages(exclude=['contrib', 'docs', 'test'])" }) setup = Setup(mdl) setup.add_setting('BASE') serialized_settings, _ = serialize_settings(setup) assert serialized_settings == """BASE = {
def test_serializer_can_deserialize_nested_dictionary_setting(): mdl = MockDependencyLoader() mdl.a_setting('BASE', properties={ "name": "\"setupy\"", "version": "\"0.1.0\"", "packages": "find_packages(exclude=['contrib', 'docs', 'test'])", "extra_requires": { "dev": ["\"pytest\""] } }) setup = Setup(mdl) setup.add_setting('BASE') serialized_settings, _ = serialize_settings(setup) assert serialized_settings == """BASE = {
def _make_setup_file(features, settings, include_help): if 'base' not in settings: settings.insert(0, 'base') if 'merge' not in features: features.insert(0, 'merge') setup = Setup(dependency_loader) missing_features = [] missing_settings = [] try: for f in features: setup.add_feature(f) except FeatureNotFoundError: missing_features.append(f) try: for s in settings: setup.add_setting(s) except SettingNotFoundError: missing_settings.append(s) setup_file_contents = serialize(setup, include_help) not_found_features = '\n'.join(f'# Feature {f} was not found' for f in missing_features) not_found_settings = '\n'.join(f'# Setting {s} was not found' for s in missing_settings) error_text = f'{not_found_features}\n{not_found_settings}' return f'{setup_file_contents}\n\n{error_text}'
def test_graph_should_produce_the_minimal_import_dependency_set(): mdl = MockDependencyLoader() mdl.a_feature("test", ["from setuptools import setup"]) mdl.a_feature("test2", ["from setuptools import setup"]) g = Setup(mdl) g.add_feature("test") g.add_feature("test2") assert g.imports == {"from setuptools import setup"} assert g.features == {Feature("test"), Feature("test2")}
def test_graph_should_produce_minimal_feature_dependency_set_by_name(): mdl = MockDependencyLoader() mdl.a_setting("test", features=["test3"]) mdl.a_feature("test2", features=["test3"]) mdl.a_feature("test3", imports=["from setuptools import setup"]) g = Setup(mdl) g.add_setting("test") g.add_feature("test2") assert g.imports == {"from setuptools import setup"} assert g.features == {Feature("test2"), Feature("test3")} assert g.settings == [Setting("test")]
def test_serializer_can_serialize_features(): mdl = MockDependencyLoader() mdl.a_feature("test", code="""def merge(*dicts): r = {} for d in dicts: r.update(d) return r""") mdl.a_feature("test2", code="""def merge(*dicts): r = {} for d in dicts: r.update(d) return r""") setup = Setup(mdl) setup.add_feature("test") setup.add_feature("test2") assert serialize_features(setup) == """def merge(*dicts):