def test_update_state(self): """ Ensure we can write to the state configuration file """ ExampleEditor = EditorBaseKeyword( DEBUG_BUILD_CONFIG, 'example', 'this is an example of the base class') current_state = read_state(DEBUG_BUILD_CONFIG) self.assertTrue(current_state.editors == []) # "install" the current keyword ExampleEditor.rewrite_state(arguments=[ExampleEditor.name], install=True) installed_example_state = read_state(DEBUG_BUILD_CONFIG) self.assertTrue( installed_example_state.editors == [ExampleEditor.name]) # "remove" the current keword ExampleEditor.rewrite_state(arguments=[ExampleEditor.name], install=False) removed_example_state = read_state(DEBUG_BUILD_CONFIG) self.assertTrue(removed_example_state.editors == [])
def test_add(self): """ Install eclipse and check the state path """ before_install = read_state(self.keyword.build_config) self.assertTrue(self.keyword.name not in self.obtain_correct_attribute( before_install)) self.keyword.add() after_install = read_state(self.keyword.build_config) self.assertTrue( self.keyword.name in self.obtain_correct_attribute(after_install))
def test_install_atom(self): """ This is a higher level testing of AtomKeyword Please consult UnitTests/Editors/test_atom_keyword.py for a micro perspective """ self.init.install_atom(write=True) current_state = read_state(self.init.build_config) self.assertTrue("atom" in current_state.editors) AtomKeyword(self.init.build_config).remove(write=True) new_state = read_state(self.init.build_config) self.assertTrue(new_state.editors == [])
def test_remove_custom(self): helper_remove = AddRemoveHelper(DEBUG_BUILD_CONFIG, 'remove') __search = helper_remove.search("ruby") # Test Remove helper_remove.run_commands(container=[__search], install=False) updated_state = read_state(DEBUG_BUILD_CONFIG) self.assertTrue("ruby" not in updated_state.installed)
def currently_installed_editors(build_config: BuildConfig) -> list: """ GOAL: list all installed editors in a formatted list """ return [ f'{"- ": >4} {element}' for element in read_state(build_config).editors]
def currently_installed_targets(build_config: BuildConfig) -> list: """ GOAL: list all installed codewords in a formatted list """ return [ f'{"- ": >4} {element}' for element in read_state(build_config).installed]
def test_remove(self): """ Remove eclipse and check the state path """ self.keyword.remove() after_removal = read_state(self.keyword.build_config) self.assertTrue(self.keyword.name not in self.obtain_correct_attribute( after_removal))
def generic_check_add(self): """ Ensure the keyword installs properly """ before_install = read_state(self.keyword.build_config) self.assertTrue(self.keyword.name not in self.obtain_correct_attribute( before_install)) self.keyword.add() after_install = read_state(self.keyword.build_config) self.assertTrue( self.keyword.name in self.obtain_correct_attribute(after_install)) try: self.assertTrue( all([ self.keyword.is_deb_package_installed(pkg) for pkg in self.keyword.packages ])) except EnvironmentError: self.assertTrue(False)
def test_rewrite_state_install(self): """ Test if the program can update the state """ original_state = read_state(DEBUG_BUILD_CONFIG) helper = AddRemoveHelper(DEBUG_BUILD_CONFIG, 'rewriter') example_keyword = TMuxKeyword(DEBUG_BUILD_CONFIG) helper.rewrite_state(keyword=example_keyword, install=True) # install the keyword updated_state = read_state(DEBUG_BUILD_CONFIG) # note the state helper.rewrite_state(keyword=example_keyword, install=False) # remove the keyword reverted_state = read_state(DEBUG_BUILD_CONFIG) # note the state again # check if the new state is equal to the snap shot self.assertTrue(original_state == reverted_state) """
def test_run_commands_remove(self): helper_remove = AddRemoveHelper(DEBUG_BUILD_CONFIG, 'remove') # Test Remove helper_remove.run_commands(container=[ (True, TMuxKeyword(DEBUG_BUILD_CONFIG)) ], install=False) updated_state = read_state(DEBUG_BUILD_CONFIG) self.assertTrue("tmux" not in updated_state.installed) try: helper_remove.run_commands( [(True, AllKeyword(DEBUG_BUILD_CONFIG))], install=False) except UsageError: pass else: self.assertTrue(False)
def test_run_commands_install(self): helper_add = AddRemoveHelper(DEBUG_BUILD_CONFIG, 'add') # Test install helper_add.run_commands(container=[(True, TMuxKeyword(DEBUG_BUILD_CONFIG))], install=True) updated_state = read_state(DEBUG_BUILD_CONFIG) # note the state self.assertTrue("tmux" in updated_state.installed) # Test reinstall try: helper_add.run_commands(container=[ (True, TMuxKeyword(DEBUG_BUILD_CONFIG)) ], install=True) except UsageError: pass else: self.assertTrue(False)
def generic_check_remove(self): """ Ensure the keyword is removed properly """ self.keyword.remove() after_removal = read_state(self.keyword.build_config) self.assertTrue(self.keyword.name not in self.obtain_correct_attribute( after_removal)) try: self.assertTrue( self.keyword.is_deb_package_installed(self.keyword.name) or all([ self.keyword.is_deb_package_installed(pkg) for pkg in self.keyword.packages ])) except EnvironmentError: self.assertTrue(False) if (hasattr(self.keyword, 'file_footprint')): for _, artifcat in self.keywords.file_footprint.items(): self.assertFalse(artifcat.is_file())
def test_read_state(self): # init has not been completed yet # OSError, FileNotFoundError self.Init.remove_state_directory() try: read_state(DEBUG_BUILD_CONFIG) except (FileNotFoundError, EnvironmentError): self.Init.create_state_directory() self.state.write() else: self.assertTrue(False) original_state = read_state(DEBUG_BUILD_CONFIG) corrupted_payload = {"malformed": "payload"} with open(DEBUG_BUILD_CONFIG.state_path, "w") as fp: json.dump(corrupted_payload, fp) invalid_version = { "version": "baconandeggs", "installed": [], "editors": [] } with open(DEBUG_BUILD_CONFIG.state_path, "w") as fp: json.dump(invalid_version, fp) # malformed version # packaging.version.InvalidVersion try: read_state(DEBUG_BUILD_CONFIG) except EnvironmentError: self.state = self.another else: self.assertTrue(False) # missing data # KeyError try: read_state(DEBUG_BUILD_CONFIG) except EnvironmentError: self.state = self.another else: self.assertTrue(False) invalid_data_components = { "version": "1.0", "installed": set(), "editors": [] } # Data is incorrect # ValueError <- given in constructor of State() try: read_state(DEBUG_BUILD_CONFIG) except EnvironmentError: self.state = self.another else: self.assertTrue(False)