class TestYamlMixin(object): """ Specifically test mixin separate from targets. """ def setup(self): self.config_file = os.path.join(tc.STAGING, 'file.yaml') self.config = YamlMixin(self.config_file) def teardown(self): tc.delete_it(self.config_file) def test_filename_get(self): assert self.config.filename == self.config_file @mock.patch('pakit.conf.logging') def test_filename_set(self, mock_log): new_file = self.config_file + '2' self.config.filename = new_file mock_log.error.assert_called_with('File not found: %s', new_file) assert self.config.filename == new_file def test_read_from(self): with open(self.config.filename, 'wb') as fout: fout.write('hello: world\n'.encode()) obj = self.config.read_from() assert isinstance(obj, dict) assert obj['hello'] == 'world' @mock.patch('pakit.conf.logging') def test_read_from_file_invalid(self, mock_log): assert not os.path.exists(self.config.filename) self.config.read_from() assert mock_log.error.called def test_write_to(self): self.config.write_to({'hello': 'world'}) assert os.path.exists(self.config.filename) with open(self.config.filename) as fin: assert fin.readlines() == ['hello: world\n']
def setup(self): self.config_file = os.path.join(tc.STAGING, 'file.yaml') self.config = YamlMixin(self.config_file)