From a555416a3e0ba9089966f480e60cb55b698e48b9 Mon Sep 17 00:00:00 2001 From: Julien Enselme Date: Thu, 29 Oct 2015 19:22:00 +0100 Subject: [PATCH] Enable tests suite - Build python3 and python2 in the same directory - Use %py2_build, %py3_build, %py2_install and %py2_install - Move python2 package in its own subpackage --- python-toml.spec | 61 ++++++++++++++++++++++++++++++++---------------- toml_test.py | 56 ++++++++++++++++++++++++++++++++++++++++++++ toml_test3.py | 11 +++++++++ 3 files changed, 108 insertions(+), 20 deletions(-) create mode 100644 toml_test.py create mode 100644 toml_test3.py diff --git a/python-toml.spec b/python-toml.spec index 24f06ba..c19e389 100644 --- a/python-toml.spec +++ b/python-toml.spec @@ -1,16 +1,21 @@ %global pypi_name toml +%global with_test 0 Name: python-%{pypi_name} Version: 0.9.1 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Python Library for Tom's Obvious, Minimal Language License: MIT URL: https://pypi.python.org/pypi/%{pypi_name} Source0: https://pypi.python.org/packages/source/t/%{pypi_name}/%{pypi_name}-%{version}.tar.gz +# Tests files are not provided in pypi release as they require toml-test to run +Source1: https://raw.githubusercontent.com/uiri/toml/da6d593944d08569e08ff32f2bb2e73da91d3578/toml_test.py +Source2: https://raw.githubusercontent.com/uiri/toml/da6d593944d08569e08ff32f2bb2e73da91d3578/toml_test3.py BuildArch: noarch BuildRequires: python2-devel +BuildRequires: golang-github-BurntSushi-toml-test %description TOML aims to be a minimal configuration file format that's easy to read due to @@ -20,9 +25,22 @@ This package loads toml file into python dictionary and dump dictionary into toml file. +%package -n python2-%{pypi_name} +Summary: Python Library for Tom's Obvious, Minimal Language +%{?python_provide:%python_provide python2-%{pypi_name}} + +%description -n python2-%{pypi_name} +TOML aims to be a minimal configuration file format that's easy to read due to +obvious semantics. TOML is designed to map unambiguously to a hash table. TOML +should be easy to parse into data structures in a wide variety of languages. +This package loads toml file into python dictionary and dump dictionary into +toml file. + + %package -n python3-%{pypi_name} Summary: Python Library for Tom's Obvious, Minimal Language BuildRequires: python3-devel +%{?python_provide:%python_provide python2-%{pypi_name}} %description -n python3-%{pypi_name} TOML aims to be a minimal configuration file format that's easy to read due to @@ -34,35 +52,32 @@ toml file. %prep %setup -q -n %{pypi_name}-%{version} -rm -rf %{py3dir} -cp -a . %{py3dir} +# Copy test files and make them executable so toml-test can work +cp -a %{SOURCE1} %{SOURCE2} . +chmod +x toml_test.py toml_test3.py + %build -pushd %{py3dir} -%{__python3} setup.py build -popd - -%{__python2} setup.py build +%py2_build +%py3_build %install -pushd %{py3dir} -%{__python3} setup.py install -O1 --skip-build --root %{buildroot} -popd - -%{__python2} setup.py install -O1 --skip-build --root %{buildroot} +%py2_install +%py3_install %check -# No test suite at present, so we'll just try importing -pushd %{py3dir} -PYTHONPATH=%{buildroot}%{python3_sitelib} %{__python3} -c "import toml" -popd - -PYTHONPATH=%{buildroot}%{python2_sitelib} %{__python2} -c "import toml" +# Using the language independent toml-test suite to launch tests +# link the the tests files +%if 0%{with_test} +ln -s /usr/share/toml-test/tests tests +toml-test $(pwd)/toml_test3.py +toml-test $(pwd)/toml_test.py +%endif -%files +%files -n python2-%{pypi_name} %license LICENSE %doc README.rst %{python2_sitelib}/%{pypi_name}-%{version}-py%{python2_version}.egg-info @@ -76,6 +91,12 @@ PYTHONPATH=%{buildroot}%{python2_sitelib} %{__python2} -c "import toml" %{python3_sitelib}/__pycache__/%{pypi_name}.cpython-*.py* %changelog +* Sat Aug 8 2015 Julien Enselme - 0.9.1-2 +- Enable tests suite +- Build python3 and python2 in the same directory +- Use %%py2_build, %%py3_build, %%py2_install and %%py2_install +- Move python2 package in its own subpackage + * Sat Jul 11 2015 Fedora Release Monitoring - 0.9.1-1 - Update to 0.9.1 (#1242131) diff --git a/toml_test.py b/toml_test.py new file mode 100644 index 0000000..f399c05 --- /dev/null +++ b/toml_test.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python2 + +import datetime +import json +import sys +import toml + +try: + _range = xrange + iteritems = dict.iteritems +except NameError: + unicode = str + _range = range + basestring = str + unichr = chr + iteritems = dict.items + long = int + +def tag(value): + if isinstance(value, dict): + d = { } + for k, v in iteritems(value): + d[k] = tag(v) + return d + elif isinstance(value, list): + a = [] + for v in value: + a.append(tag(v)) + try: + a[0]["value"] + except KeyError: + return a + except IndexError: + pass + return {'type': 'array', 'value': a} + elif isinstance(value, basestring): + return {'type': 'string', 'value': value} + elif isinstance(value, bool): + return {'type': 'bool', 'value': str(value).lower()} + elif isinstance(value, int): + return {'type': 'integer', 'value': str(value)} + elif isinstance(value, long): + return {'type': 'integer', 'value': str(value)} + elif isinstance(value, float): + return {'type': 'float', 'value': repr(value)} + elif isinstance(value, datetime.datetime): + sdate = value.strftime('%Y-%m-%dT%H:%M:%SZ') + return {'type': 'datetime', 'value': sdate} + assert False, 'Unknown type: %s' % type(value) + + +if __name__ == '__main__': + tdata = toml.loads(sys.stdin.read()) + tagged = tag(tdata) + print(json.dumps(tagged)) + diff --git a/toml_test3.py b/toml_test3.py new file mode 100644 index 0000000..84b6351 --- /dev/null +++ b/toml_test3.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +import toml_test +import toml +import sys +import json + +if __name__ == '__main__': + tdata = toml.loads(sys.stdin.read()) + tagged = toml_test.tag(tdata) + print(json.dumps(tagged))