def setUp(self): with open(self.cache_file, 'w') as files: files.write('{}\n'.format(self.dep)) os.utime(self.app, (-1, 30)) os.utime(self.dep, (-1, 60)) os.utime(self.cache_file, (-1, 100)) self.out.touch() os.utime(self.out, (-1, 100)) self.flc = FilesListComparator(self.out)
class TestFilesListComparator(unittest.TestCase): @classmethod def setUpClass(cls): cls.FS = FS.joinpath('1') cls.cache_file = cls.FS.joinpath('.out.js.files') cls.out = cls.FS.joinpath('out.js') cls.app = cls.FS.joinpath('app/app.js') cls.dep = cls.FS.joinpath('views/view.js') cls.dep_utime = cls.dep.stat().st_mtime cls.app_utime = cls.app.stat().st_mtime @classmethod def tearDownClass(cls): cls.out.remove() cls.cache_file.remove() os.utime(cls.dep, (-1, cls.dep_utime)) os.utime(cls.app, (-1, cls.app_utime)) def setUp(self): with open(self.cache_file, 'w') as files: files.write('{}\n'.format(self.dep)) os.utime(self.app, (-1, 30)) os.utime(self.dep, (-1, 60)) os.utime(self.cache_file, (-1, 100)) self.out.touch() os.utime(self.out, (-1, 100)) self.flc = FilesListComparator(self.out) def tearDown(self): try: os.unlink(self.cache_file) except: pass def test_is_up_to_date_false(self): assert self.flc.is_up_to_date() is False def test_is_up_to_date_dep(self): os.utime(self.dep, (-1, 101)) assert self.flc.is_up_to_date() is True def test_is_up_to_date_missing_dep(self): with open(self.cache_file, 'w') as files: files.write('{}\n'.format('/abc/def')) assert self.flc.is_up_to_date() is True def test_is_up_to_date_no_out(self): self.out.remove() assert self.flc.is_up_to_date() is True def test_write(self): buffer = io.StringIO() with mock.patch('sett.requirejs.open') as open: open.return_value.__enter__.return_value.write.side_effect = buffer.write self.flc.write(['/abc/views/view.js', '/abc/app/app.js']) open.assert_called_once_with(self.cache_file, 'w') self.assertEqual(buffer.getvalue(), '/abc/views/view.js\n/abc/app/app.js\n')