def test_clean_file(self): current_dir = os.path.dirname(__file__) artifacts_dir = os.path.join(current_dir, self._artifacts_dir_name) extensions = [p.InputFileType.json, p.InputFileType.text] for ext in extensions: full_input_path = os.path.join(artifacts_dir, "clean_file_sample" + ext) raw_data = p.get_file_contents(full_input_path) self.assertIsNotNone(raw_data) # Test all option check_against = self._get_test_data_for_option(raw_data) self._test_clean_file(full_input_path, check_against) # Test individual options options = [ p.OPT.URL, p.OPT.MENTION, p.OPT.HASHTAG, p.OPT.RESERVED, p.OPT.EMOJI, p.OPT.SMILEY, p.OPT.NUMBER ] for opt in options: check_against = self._get_test_data_for_option(raw_data, opt) self._test_clean_file(full_input_path, check_against, opt)
def test_write_to_text_file(self): # Test file was created output_path = self._write_test_contents_to_cur_dir(p.InputFileType.text) self.assertTrue(os.path.exists(output_path)) file_contents = p.get_file_contents(output_path) # Check the contents of written file is same as the one defined in this class p.are_lists_equal(file_contents, self._test_file_contents)
def _test_clean_file(self, full_input_path, check_against, *options): output_path = p.clean_file(full_input_path, True, options) self.assertTrue(os.path.exists(output_path)) clean_content = p.get_file_contents(output_path) p.are_lists_equal(clean_content, check_against)