Skip to contentSkip to conversation

support/tests: allow properly indented config fragment

PATCH New Yann E. MORIN 3 participants 4 messages Jul 18, 2017 – Jul 19, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 support/tests: allow properly indented config fragment

Currently, defining a config fragment in the runtime test infra requires that the fragment not to be indented. This is beark, and causes grievance when looking at the code (e.g. to fix it).

Just strip out all leading spaces/tabs when writing the configuration lines into the config file, allowing in-line indented config fragments, like so:

    class TestFoo(bla):
        config = bla.config + \
            """
            FOO=y
            # BAR is not set
            """
Cc Thomas Petazzoni <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

---
Changes v2 -> v3:
- use and fix code snippet provided by Arnout, thanks! ;-)
- do it in our base test class, not on the builder class (Arnout)

Changes v1 -> v2:
- add example in commit log (Thomas)

---
 support/testing/infra/basetest.py | 1 +
 1 file changed, 1 insertion(+)
support/testing/infra/basetest.py +1 -0
index 1a082bb441..07c180e232 100644
@@ -41,6 +41,7 @@ class BRTest(unittest.TestCase):
         self.testname = self.__class__.__name__
         self.builddir = self.outputdir and os.path.join(self.outputdir, self.testname)
         self.emulator = None
+        self.config = '\n'.join([line.lstrip() for line in self.config.splitlines()])
 
     def show_msg(self, msg):
         print "{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
Signature · 1 line
2.11.0
#1 lore raw

PATCH v3 1/1 support/tests: allow properly indented config fragment

Hello,

Quoted 15 lines · Yann E. MORIN

Currently, defining a config fragment in the runtime test infra requires that the fragment not to be indented. This is beark, and causes grievance when looking at the code (e.g. to fix it).

Just strip out all leading spaces/tabs when writing the configuration lines into the config file, allowing in-line indented config fragments, like so:

    class TestFoo(bla):
        config = bla.config + \
            """
            FOO=y
            # BAR is not set
            """
Quoted 8 lines
Cc Thomas Petazzoni <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

---
Changes v2 -> v3:
- use and fix code snippet provided by Arnout, thanks! ;-)
- do it in our base test class, not on the builder class (Arnout)

Applied to master, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH v3 1/1 support/tests: allow properly indented config fragment

In reply to Yann E. MORIN
Quoted 15 lines · Yann E. MORIN

Currently, defining a config fragment in the runtime test infra requires that the fragment not to be indented. This is beark, and causes grievance when looking at the code (e.g. to fix it).

Just strip out all leading spaces/tabs when writing the configuration lines into the config file, allowing in-line indented config fragments, like so:

    class TestFoo(bla):
        config = bla.config + \
            """
            FOO=y
            # BAR is not set
            """
Quoted 3 lines
Cc Thomas Petazzoni <[email protected]>
Cc Arnout Vandecappelle <[email protected]>
Quoted 17 lines

---
Changes v2 -> v3:
- use and fix code snippet provided by Arnout, thanks! ;-)
- do it in our base test class, not on the builder class (Arnout)

Changes v1 -> v2:
- add example in commit log (Thomas)

---
 support/testing/infra/basetest.py | 1 +
 1 file changed, 1 insertion(+)
support/testing/infra/basetest.py +0 -0
index 1a082bb441..07c180e232 100644

support/testing/infra/basetest.py class BRTest(unittest.TestCase): · line 44

Quoted 4 lines
support/testing/infra/basetest.py +1 -0
@@ -41,6 +41,7 @@ class BRTest(unittest.TestCase):
         self.testname = self.__class__.__name__
         self.builddir = self.outputdir and os.path.join(self.outputdir, self.testname)
         self.emulator = None
+        self.config = '\n'.join([line.lstrip() for line in self.config.splitlines()])

It would also be nice to move the setting of jlevel to the constructor. But
heck, there's probably a lot that would be nice to improve in the testing infra :-)

Regards,
Arnout

Quoted 4 lines
support/testing/infra/basetest.py +0 -0
     def show_msg(self, msg):
         print "{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"),
 
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#3 lore raw

PATCH v3 1/1 support/tests: allow properly indented config fragment

Hello,

Quoted 16 lines · Arnout Vandecappelle
Quoted 15 lines · Yann E. MORIN

Currently, defining a config fragment in the runtime test infra requires that the fragment not to be indented. This is beark, and causes grievance when looking at the code (e.g. to fix it).

Just strip out all leading spaces/tabs when writing the configuration lines into the config file, allowing in-line indented config fragments, like so:

    class TestFoo(bla):
        config = bla.config + \
            """
            FOO=y
            # BAR is not set
            """
Quoted 5 lines
Quoted 3 lines
Cc Thomas Petazzoni <[email protected]>
Cc Arnout Vandecappelle <[email protected]>

I already applied yesterday evening:
https://git.buildroot.org/buildroot/commit/?id=cf3cd4388a652c9af27ef1c35622e2d0a55b99a9.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com