Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
test_setopt.py41 linesDownload Raw Back to tests
1import configparser2 3from setuptools.command import setopt4 5 6class TestEdit:7    @staticmethod8    def parse_config(filename):9        parser = configparser.ConfigParser()10        with open(filename, encoding='utf-8') as reader:11            parser.read_file(reader)12        return parser13 14    @staticmethod15    def write_text(file, content):16        with open(file, 'wb') as strm:17            strm.write(content.encode('utf-8'))18 19    def test_utf8_encoding_retained(self, tmpdir):20        """21        When editing a file, non-ASCII characters encoded in22        UTF-8 should be retained.23        """24        config = tmpdir.join('setup.cfg')25        self.write_text(str(config), '[names]\njaraco=джарако')26        setopt.edit_config(str(config), dict(names=dict(other='yes')))27        parser = self.parse_config(str(config))28        assert parser.get('names', 'jaraco') == 'джарако'29        assert parser.get('names', 'other') == 'yes'30 31    def test_case_retained(self, tmpdir):32        """33        When editing a file, case of keys should be retained.34        """35        config = tmpdir.join('setup.cfg')36        self.write_text(str(config), '[names]\nFoO=bAr')37        setopt.edit_config(str(config), dict(names=dict(oTher='yes')))38        actual = config.read_text(encoding='ascii')39        assert 'FoO' in actual40        assert 'oTher' in actual41 
codekingpro/portable-devtools · Team Ai