From 7b09ba64c0327ecea04cc95057ffa7d5c8d939c8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 5 Apr 2019 10:46:00 -0400 Subject: Add test for setopt to demonstrate that edit_config retains non-ASCII characters. --- setuptools/tests/test_setopt.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 setuptools/tests/test_setopt.py (limited to 'setuptools/tests/test_setopt.py') diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py new file mode 100644 index 00000000..2241ef73 --- /dev/null +++ b/setuptools/tests/test_setopt.py @@ -0,0 +1,36 @@ +# coding: utf-8 + +from __future__ import unicode_literals + +import io + +import six + +from setuptools.command import setopt +from setuptools.extern.six.moves import configparser + + +class TestEdit: + @staticmethod + def parse_config(filename): + parser = configparser.ConfigParser() + with io.open(filename, encoding='utf-8') as reader: + (parser.read_file if six.PY3 else parser.readfp)(reader) + return parser + + @staticmethod + def write_text(file, content): + with io.open(file, 'wb') as strm: + strm.write(content.encode('utf-8')) + + def test_utf8_encoding_retained(self, tmpdir): + """ + When editing a file, non-ASCII characters encoded in + UTF-8 should be retained. + """ + config = tmpdir.join('setup.cfg') + self.write_text(config, '[names]\njaraco=йарацо') + setopt.edit_config(str(config), dict(names=dict(other='yes'))) + parser = self.parse_config(str(config)) + assert parser['names']['jaraco'] == 'йарацо' + assert parser['names']['other'] == 'yes' -- cgit v1.2.1 From b336e83a63722b3a3e4d3f1779686149d5cef8d1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 5 Apr 2019 10:49:23 -0400 Subject: Add compatibility for Python 2 --- setuptools/tests/test_setopt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/tests/test_setopt.py') diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index 2241ef73..7c803500 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -29,8 +29,8 @@ class TestEdit: UTF-8 should be retained. """ config = tmpdir.join('setup.cfg') - self.write_text(config, '[names]\njaraco=йарацо') + self.write_text(str(config), '[names]\njaraco=йарацо') setopt.edit_config(str(config), dict(names=dict(other='yes'))) parser = self.parse_config(str(config)) - assert parser['names']['jaraco'] == 'йарацо' - assert parser['names']['other'] == 'yes' + assert parser.get('names', 'jaraco') == 'йарацо' + assert parser.get('names', 'other') == 'yes' -- cgit v1.2.1 From 7ed188bcaf38a25fb63fbb1ed3b070428ff95759 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 5 Apr 2019 11:07:02 -0400 Subject: Correct cyrillic to match preferred pronunciation. --- setuptools/tests/test_setopt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/tests/test_setopt.py') diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index 7c803500..3fb04fb4 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -29,8 +29,8 @@ class TestEdit: UTF-8 should be retained. """ config = tmpdir.join('setup.cfg') - self.write_text(str(config), '[names]\njaraco=йарацо') + self.write_text(str(config), '[names]\njaraco=джарако') setopt.edit_config(str(config), dict(names=dict(other='yes'))) parser = self.parse_config(str(config)) - assert parser.get('names', 'jaraco') == 'йарацо' + assert parser.get('names', 'jaraco') == 'джарако' assert parser.get('names', 'other') == 'yes' -- cgit v1.2.1 From 796abd8dbec884cedf326cb5f85512a5d5648c4e Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 8 Jan 2020 19:10:11 +0200 Subject: Fix for Python 4: replace unsafe six.PY3 with PY2 --- setuptools/tests/test_setopt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/tests/test_setopt.py') diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index 3fb04fb4..1b038954 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -15,7 +15,7 @@ class TestEdit: def parse_config(filename): parser = configparser.ConfigParser() with io.open(filename, encoding='utf-8') as reader: - (parser.read_file if six.PY3 else parser.readfp)(reader) + (parser.readfp if six.PY2 else parser.read_file)(reader) return parser @staticmethod -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/tests/test_setopt.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'setuptools/tests/test_setopt.py') diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index 1b038954..0163f9af 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -1,13 +1,7 @@ -# coding: utf-8 - -from __future__ import unicode_literals - import io - -import six +import configparser from setuptools.command import setopt -from setuptools.extern.six.moves import configparser class TestEdit: @@ -15,7 +9,7 @@ class TestEdit: def parse_config(filename): parser = configparser.ConfigParser() with io.open(filename, encoding='utf-8') as reader: - (parser.readfp if six.PY2 else parser.read_file)(reader) + parser.read_file(reader) return parser @staticmethod -- cgit v1.2.1 From de5b49b73864d3de963ab24e928c189284ba35f1 Mon Sep 17 00:00:00 2001 From: Antonio Russo Date: Mon, 6 Sep 2021 19:03:28 -0600 Subject: Preserve case of keys during edit_config This aligns behavior with 21b122e06969a9d85c65ce8276519d34da7dc747 during source distribution generation. Signed-off-by: Antonio Russo --- setuptools/tests/test_setopt.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'setuptools/tests/test_setopt.py') diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index 0163f9af..a34d3f61 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -28,3 +28,14 @@ class TestEdit: parser = self.parse_config(str(config)) assert parser.get('names', 'jaraco') == 'джарако' assert parser.get('names', 'other') == 'yes' + + def test_case_retained(self, tmpdir): + """ + When editing a file, case of keys should be retained. + """ + config = tmpdir.join('setup.cfg') + self.write_text(str(config), '[names]\nFoO=bAr') + setopt.edit_config(str(config), dict(names=dict(oTher='yes'))) + parser = self.parse_config(str(config)) + assert parser.get('names', 'FoO') == 'bAr' + assert parser.get('names', 'oTher') == 'yes' -- cgit v1.2.1 From c020053fa6a3e3abf2686ad8b6eb95efa8794c9f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 8 Sep 2021 21:13:11 -0400 Subject: Add test capturing missed expectation. Ref #2773. --- setuptools/tests/test_setopt.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'setuptools/tests/test_setopt.py') diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index 0163f9af..61dc68b6 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -28,3 +28,11 @@ class TestEdit: parser = self.parse_config(str(config)) assert parser.get('names', 'jaraco') == 'джарако' assert parser.get('names', 'other') == 'yes' + + def test_case_retained(self, tmpdir): + """ + """ + config = tmpdir.join('setup.cfg') + self.write_text(str(config), '[names]\nJARACO=jaraco') + setopt.edit_config(str(config), dict()) + assert 'JARACO' in config.read_text(encoding='ascii') -- cgit v1.2.1