class WordProcessingTest(unittest.TestCase): def setUp(self): self.textfile = 'in' self.emptyfile = 'out' self.sample = 'no_file_disk' self.data = 'qwerty \n !,.?:QweRty;[] \n q1W34erT78y \t soFTeq 9Softeq9 sofTEQ\n' with open(self.textfile, 'w') as f: f.write(self.data) with open(self.emptyfile, 'w') as f: f.write('') self.words_ext = Analyzer(self.textfile, self.emptyfile) self.words_ext_empty = Analyzer(self.emptyfile, self.textfile) self.words_sample = Analyzer(self.textfile, self.sample) def tearDown(self): os.unlink(self.textfile) os.unlink(self.emptyfile) try: os.unlink(self.sample) except FileNotFoundError: pass def test_WordsExtractorRun(self): self.words_ext_empty.words_processing() self.assertListEqual(self.words_ext_empty.words, []) def test_WordsWriterRun(self): self.words_sample.words_processing() assert os.path.exists(self.sample) is True def test_WordsExtractorReturn(self): self.words_ext.words_extractor() self.assertEqual(len(self.words_ext.words), 6) def test_EmptyFileProcessing(self): self.words_ext_empty.words_processing() self.assertEqual(len(self.words_ext_empty.words), 0) def test_EmptyFileProcessingList(self): self.words_ext_empty.words_processing() self.assertListEqual(self.words_ext_empty.words, []) def test_RemoveNonAlphaWords(self): self.words_ext.words_processing() self.assertEqual(len(self.words_ext.words), 2)
class WordExtractorTest(unittest.TestCase): def setUp(self): self.textfile = 'in' self.emptyfile = 'out' self.data = 'qwerty \n Qwerty \n !,.?:QweRty;[] \n q1W34erT78y' with open(self.textfile, 'w') as f: f.write(self.data) with open(self.emptyfile, 'w') as f: f.write('') self.words_ext = Analyzer(self.textfile, self.emptyfile) self.words_ext_empty = Analyzer(self.emptyfile, self.textfile) def tearDown(self): os.unlink(self.textfile) os.unlink(self.emptyfile) def test_IsInstanceCreate(self): self.assertIsInstance(self.words_ext, Analyzer) def test_WordsListInit(self): self.words_ext_empty.words_extractor() self.assertListEqual(self.words_ext_empty.words, []) def test_EmptyFile(self): self.words_ext_empty.words_extractor() self.assertEqual(len(self.words_ext_empty.words), 0) def test_CounterSuccess(self): self.words_ext.words_extractor() self.assertEqual(len(self.words_ext.words), 4) def test_CounterFailed(self): self.words_ext.words_extractor() self.assertNotEqual(len(self.words_ext.words), not 4) def test_ValidData(self): self.words_ext.words_extractor() self.assertListEqual(self.words_ext.words, ['qwerty', 'qwerty', 'qwerty', 'q1w34ert78y'])