def setUp(self): # self.state_handler = TestGitFlowHelper.init_repo(INIT_VERSION) # # self.state_handler: StateHandler = StateHandler(TestGitFlowHelper.DIR_PATH_TEST).load_file_config() self.state_handler: StateHandler = StateHandler(Path('/tmp/test')) self.git: GitCmd = GitCmd(state_handler=self.state_handler) self.git_flow: GitFlowCmd = GitFlowCmd( state_handler=self.state_handler)
def setUp(self): self.initial_version: Version = Version(1, 8, 9) self.state_handler: StateHandler = StateHandler(Path('.')) state: State = State() state.version = self.initial_version state.level = Level.STABLE state.schemes = [Schemes.PACKAGE] self.state_handler.state = state
def init_repo(cls, version: str) -> StateHandler: cls.clean_workdir() cls.mount_workdir_and_clone() state_handler: StateHandler = StateHandler(cls.DIR_PATH_TEST) state_handler.state = cls.fake_state(version) Git(state_handler).build_branch(Branches.DEVELOP).with_action( Actions.INIT).process() Log.info('init repo : ' + str(version)) return state_handler
def clean_remote_repo(cls, version: Version = Version(0, 0, 0)): git: GitCmd = GitCmd( state_handler=StateHandler(TestGitFlowHelper.DIR_PATH_TEST)) git.checkout(Branches.MASTER).reset_to_tag(cls.TAG_INIT) \ .push_force() \ .delete_remote_branch_from_name(Branches.DEVELOP.value) \ .delete_tag(str(version), remote=True) \ .delete_tag('-'.join([str(version.next_minor()), Level.DEV.value]), remote=True) Log.info('clean remote repo : ' + str(version))
def test_should_plan_release_not_empty(self): TestPackageHelper.mount_workdir_with_dev_dependencies() state: State = TestPackageHelper.fake_state() state_handler: StateHandler = StateHandler( TestPackageHelper.DIR_PATH_TEST) state_handler.state = state package: PackageScheme = PackageScheme(state_handler) dependencies: Dependencies = package.release_precheck() self.assertIsInstance(dependencies, Dependencies) self.assertNotEqual(len(dependencies), 0)
def test_should_dev_dependencies_empty(self): TestSchemesHelper.mount_workdir_without_dev_dependencies() state_handler: StateHandler = StateHandler( TestSchemesHelper.DIR_PATH_TEST).load_file_config() version_control: Type[VersionControl] = VersionControlBuilder.build( VersionController.GITFLOW, state_handler) action: Type[Action] = ActionBuilder.build( Actions.PRECHECK, version_control, Branches.RELEASE, state_handler, {}, ).process()
def test_should_change_version(self): TestPackageHelper.mount_workdir_without_dev_dependencies() state: State = TestPackageHelper.fake_state() package_handler_before = PackageFileHandler( TestPackageHelper.DIR_PATH_TEST) self.assertNotEqual(str(state.version), package_handler_before.get_version()) state_handler: StateHandler = StateHandler( TestPackageHelper.DIR_PATH_TEST) state_handler.state = state package: PackageScheme = PackageScheme(state_handler) package.set_version() package_handler_after = PackageFileHandler( TestPackageHelper.DIR_PATH_TEST) self.assertEqual(str(state.version), package_handler_after.get_version())
def mount_workdir_and_clone(cls): cls.DIR_PATH_TEST.mkdir() git: GitCmd = GitCmd( state_handler=StateHandler(TestGitFlowHelper.DIR_PATH_TEST)) git.clone(cls.REPO_URL)
import unittest from pathlib import Path from FlexioFlow.StateHandler import StateHandler from VersionControl.Git.Branches.GitFlowCmd import GitFlowCmd from VersionControl.Git.GitCmd import GitCmd from Branches.Branches import Branches from VersionControlProvider.Github.Repo import Repo from tests.VersionControl.GitFlow.TestGitFlowHelper import TestGitFlowHelper tag_test: str = 'tag_test' git: GitCmd = GitCmd( state_handler=StateHandler(TestGitFlowHelper.DIR_PATH_TEST)) INIT_VERSION: str = '0.0.0' class TestGitCmd(unittest.TestCase): def setUp(self): # self.state_handler = TestGitFlowHelper.init_repo(INIT_VERSION) # # self.state_handler: StateHandler = StateHandler(TestGitFlowHelper.DIR_PATH_TEST).load_file_config() self.state_handler: StateHandler = StateHandler(Path('/tmp/test')) self.git: GitCmd = GitCmd(state_handler=self.state_handler) self.git_flow: GitFlowCmd = GitFlowCmd( state_handler=self.state_handler) def test_has_branch(self): has_branch: bool = self.git.local_branch_exists('hotfix') self.assertTrue(has_branch)
def __ensure_state_handler(self): if self.__state_handler is None: self.__state_handler = StateHandler(self.__dir_path) if self.__branch_action not in [BranchActions.INIT]: self.__state_handler.load_file_config()
class FlexioFlow: __branch: Optional[Branches] = None __branch_action: Optional[BranchActions] = None __config_handler: ConfigHandler __core_action: Optional[ActionsCore] = None __poom_ci_actions: Optional[PoomCiActions] = None __dir_path: Path __issue_action: Optional[IssueActions] = None __topic_action: Optional[TopicActions] = None __options: Dict[str, Union[str, Schemes, bool]] __state_handler: Optional[StateHandler] = None __version_controller: VersionController __version_control: VersionControl = None def __init__(self, config: ExecutorConfig): self.__task: Task = config.task self.__version_controller: VersionController = config.version_controller self.__branch_action: Optional[BranchActions] = config.branch_action self.__issue_action: Optional[IssueActions] = config.issue_action self.__topic_action: Optional[TopicActions] = config.topic_action self.__core_action: Optional[ActionsCore] = config.core_action self.__poom_ci_actions: Optional[ PoomCiActions] = config.poom_ci_actions self.__branch: Optional[Branches] = config.branch self.__options: Options = config.options if not config.version_dir.is_dir(): raise NotADirectoryError self.__dir_path: Path = config.version_dir self.__config_handler: ConfigHandler = config.config_handler def __ensure_state_handler(self): if self.__state_handler is None: self.__state_handler = StateHandler(self.__dir_path) if self.__branch_action not in [BranchActions.INIT]: self.__state_handler.load_file_config() def __ensure_version_control(self): self.__ensure_state_handler() if self.__version_control is None: self.__version_control: VersionControl = VersionControlBuilder.build( self.__version_controller, self.__state_handler, self.__config_handler) def __ensure_config_handler(self): self.__config_handler.load_file_config() def __process_subject_core(self): if self.__core_action is None: raise ValueError('should have Action') Core(action=self.__core_action, options=self.__options, config_handler=self.__config_handler).process() def __process_subject_version(self): self.__ensure_state_handler() Version(state_handler=self.__state_handler, options=self.__options).process() def __process_subject_convert(self): Convert(options=self.__options).process() def __process_subject_issue(self): if self.__issue_action is None: raise ValueError('should have Action') self.__ensure_state_handler() self.__ensure_config_handler() self.__ensure_version_control() if not self.__config_handler.has_issuer(): raise NoIssuerConfigured() Issue(action=self.__issue_action, state_handler=self.__state_handler, version_control=self.__version_control, config_handler=self.__config_handler, options=self.__options).process() def __process_subject_topic(self): if self.__topic_action is None: raise ValueError('should have Action') self.__ensure_state_handler() self.__ensure_config_handler() self.__ensure_version_control() if not self.__config_handler.has_topicer(): raise NoTopicerConfigured() Topic(action=self.__topic_action, state_handler=self.__state_handler, version_control=self.__version_control, config_handler=self.__config_handler, options=self.__options).process() def __process_branch_action(self): if self.__branch_action is None: raise ValueError('should have Action') self.__ensure_state_handler() self.__ensure_config_handler() self.__ensure_version_control() self.__ensure_precheck() ActionBuilder.build(action=self.__branch_action, version_control=self.__version_control, branch=self.__branch, state_handler=self.__state_handler, options=self.__options, config_handler=self.__config_handler).process() def __process_poom_ci(self): if self.__poom_ci_actions is None: raise ValueError('should have Action') self.__ensure_state_handler() PoomCiDependency(action=self.__poom_ci_actions, state_handler=self.__state_handler, options=self.__options).process() def __ensure_precheck(self): if self.__branch_action == BranchActions.FINISH and self.__branch == Branches.RELEASE: ActionBuilder.build( action=BranchActions.PRECHECK, version_control=self.__version_control, branch=self.__branch, state_handler=self.__state_handler, options=self.__options, config_handler=self.__config_handler).process() def process(self): if self.__task is Task.CORE: self.__process_subject_core() elif self.__task is Task.VERSION: self.__process_subject_version() elif self.__task is Task.CONVERT: self.__process_subject_convert() elif self.__task is Task.ISSUE: self.__process_subject_issue() elif self.__task is Task.TOPICS: self.__process_subject_topic() elif self.__task is Task.BRANCH: self.__process_branch_action() elif self.__task is Task.POOM_CI: self.__process_poom_ci() else: raise NotImplementedError()
def fake_state_handler(cls) -> StateHandler: state_handler: StateHandler = StateHandler(cls.DIR_PATH_TEST) state_handler.state = cls.fake_state() return state_handler
def __get_develop_state(self) -> State: git.checkout(Branches.DEVELOP) state_handler_after: StateHandler = StateHandler( TestGitFlowHelper.DIR_PATH_TEST).load_file_config() return state_handler_after.state