提交 6149e2dc 编写于 作者: C Cleber Rosa

Selftests: remove evil "simple import magic"

Even though I may be the one to blame about coming up with this
"simple import magic", I believe it was a mistake and we should get
rid of them.

There are a couple of other ways to actually do development out of
of a source tree, including running unittests that do not require
this amount of boiler plate code. Examples include just setting
the PYTHONPATH environment variable to actually run (setuptools based)
`python setup.py develop`.

The little bits of what looks like the import magic that was left, is
not really import magic. It's just that functional tests need to locate
the Avocado source tree base directory to run the test runner from it.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 333e439b
...@@ -6,12 +6,6 @@ This is geared towards documentation build regression testing. ...@@ -6,12 +6,6 @@ This is geared towards documentation build regression testing.
import os import os
import sys import sys
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', '..')
basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process from avocado.utils import process
......
...@@ -7,17 +7,15 @@ if sys.version_info[:2] == (2, 6): ...@@ -7,17 +7,15 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core import data_dir from avocado.core import data_dir
from avocado.core import job_id from avocado.core import job_id
from avocado.utils import process from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
class ArgumentParsingTest(unittest.TestCase): class ArgumentParsingTest(unittest.TestCase):
def test_unknown_command(self): def test_unknown_command(self):
......
...@@ -11,14 +11,13 @@ if sys.version_info[:2] == (2, 6): ...@@ -11,14 +11,13 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import process
from avocado.utils import script
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
from avocado.utils import script
PASS_SCRIPT_CONTENTS = """#!/bin/sh PASS_SCRIPT_CONTENTS = """#!/bin/sh
true true
......
...@@ -4,16 +4,15 @@ import unittest ...@@ -4,16 +4,15 @@ import unittest
import tempfile import tempfile
import shutil import shutil
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado import VERSION from avocado import VERSION
from avocado.utils import process from avocado.utils import process
from avocado.utils import script from avocado.utils import script
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
SCRIPT_CONTENT = """#!/bin/sh SCRIPT_CONTENT = """#!/bin/sh
echo "Avocado Version: $AVOCADO_VERSION" echo "Avocado Version: $AVOCADO_VERSION"
echo "Avocado Test basedir: $AVOCADO_TEST_BASEDIR" echo "Avocado Test basedir: $AVOCADO_TEST_BASEDIR"
......
...@@ -4,13 +4,11 @@ import unittest ...@@ -4,13 +4,11 @@ import unittest
import shutil import shutil
import tempfile import tempfile
# simple magic for using scripts within a source tree from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
class GDBPluginTest(unittest.TestCase): class GDBPluginTest(unittest.TestCase):
......
...@@ -12,17 +12,16 @@ if sys.version_info[:2] == (2, 6): ...@@ -12,17 +12,16 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import wait from avocado.utils import wait
from avocado.utils import process from avocado.utils import process
from avocado.utils import script from avocado.utils import script
from avocado.utils import data_factory from avocado.utils import data_factory
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
BAD_TEST = """#!/usr/bin/env python BAD_TEST = """#!/usr/bin/env python
import signal import signal
import time import time
......
...@@ -9,14 +9,13 @@ if sys.version_info[:2] == (2, 6): ...@@ -9,14 +9,13 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import process
from avocado.utils import script
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
from avocado.utils import script
SCRIPT_CONTENT = """#!/bin/bash SCRIPT_CONTENT = """#!/bin/bash
sleep 2 sleep 2
......
...@@ -6,13 +6,11 @@ import sqlite3 ...@@ -6,13 +6,11 @@ import sqlite3
import tempfile import tempfile
import shutil import shutil
# simple magic for using scripts within a source tree from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
class JournalPluginTests(unittest.TestCase): class JournalPluginTests(unittest.TestCase):
......
...@@ -8,14 +8,13 @@ if sys.version_info[:2] == (2, 6): ...@@ -8,14 +8,13 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import script
from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import script
from avocado.utils import process
AVOCADO_TEST_OK = """#!/usr/bin/python AVOCADO_TEST_OK = """#!/usr/bin/python
from avocado import Test from avocado import Test
......
...@@ -10,13 +10,12 @@ if sys.version_info[:2] == (2, 6): ...@@ -10,13 +10,12 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
DEBUG_OUT = """Variant 16: amd@examples/mux-environment.yaml, virtio@examples/mux-environment.yaml, mint@examples/mux-environment.yaml, debug@examples/mux-environment.yaml DEBUG_OUT = """Variant 16: amd@examples/mux-environment.yaml, virtio@examples/mux-environment.yaml, mint@examples/mux-environment.yaml, debug@examples/mux-environment.yaml
/distro/mint:init => systemv@examples/mux-environment.yaml:/distro/mint /distro/mint:init => systemv@examples/mux-environment.yaml:/distro/mint
......
...@@ -11,16 +11,14 @@ if sys.version_info[:2] == (2, 6): ...@@ -11,16 +11,14 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process from avocado.utils import process
from avocado.core.output import TermSupport from avocado.core.output import TermSupport
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
class OutputTest(unittest.TestCase): class OutputTest(unittest.TestCase):
def setUp(self): def setUp(self):
......
...@@ -8,14 +8,13 @@ if sys.version_info[:2] == (2, 6): ...@@ -8,14 +8,13 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import process
from avocado.utils import script
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
from avocado.utils import script
OUTPUT_SCRIPT_CONTENTS = """#!/bin/sh OUTPUT_SCRIPT_CONTENTS = """#!/bin/sh
echo "Hello, avocado!" echo "Hello, avocado!"
......
...@@ -6,13 +6,11 @@ if sys.version_info[:2] == (2, 6): ...@@ -6,13 +6,11 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
class StandaloneTests(unittest.TestCase): class StandaloneTests(unittest.TestCase):
......
...@@ -8,13 +8,11 @@ if sys.version_info[:2] == (2, 6): ...@@ -8,13 +8,11 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
class SysInfoTest(unittest.TestCase): class SysInfoTest(unittest.TestCase):
......
...@@ -6,14 +6,13 @@ if sys.version_info[:2] == (2, 6): ...@@ -6,14 +6,13 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree from avocado.utils import script
from avocado.utils import process
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import script
from avocado.utils import process
UNITTEST_GOOD = """from avocado import Test UNITTEST_GOOD = """from avocado import Test
from unittest import main from unittest import main
......
...@@ -9,12 +9,6 @@ if sys.version_info[:2] == (2, 6): ...@@ -9,12 +9,6 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process from avocado.utils import process
FAKE_VMSTAT_CONTENTS = """#!/usr/bin/python FAKE_VMSTAT_CONTENTS = """#!/usr/bin/python
......
...@@ -4,14 +4,13 @@ import unittest ...@@ -4,14 +4,13 @@ import unittest
import tempfile import tempfile
import shutil import shutil
# simple magic for using scripts within a source tree from avocado.utils import process
from avocado.utils import script
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..') basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir) basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import process
from avocado.utils import script
SCRIPT_CONTENT = """#!/bin/bash SCRIPT_CONTENT = """#!/bin/bash
touch %s touch %s
......
...@@ -5,12 +5,6 @@ import sys ...@@ -5,12 +5,6 @@ import sys
import shutil import shutil
import random import random
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import archive from avocado.utils import archive
from avocado.utils import crypto from avocado.utils import crypto
from avocado.utils import data_factory from avocado.utils import data_factory
......
...@@ -2,12 +2,6 @@ import unittest ...@@ -2,12 +2,6 @@ import unittest
import os import os
import sys import sys
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import astring from avocado.utils import astring
......
...@@ -6,13 +6,6 @@ import tempfile ...@@ -6,13 +6,6 @@ import tempfile
from flexmock import flexmock from flexmock import flexmock
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core import settings from avocado.core import settings
......
...@@ -5,14 +5,6 @@ import unittest ...@@ -5,14 +5,6 @@ import unittest
from flexmock import flexmock from flexmock import flexmock
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import distro from avocado.utils import distro
......
...@@ -2,13 +2,6 @@ import os ...@@ -2,13 +2,6 @@ import os
import sys import sys
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import gdb from avocado.utils import gdb
......
...@@ -6,12 +6,6 @@ import argparse ...@@ -6,12 +6,6 @@ import argparse
import tempfile import tempfile
import shutil import shutil
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado import Test from avocado import Test
from avocado.core.plugins import jsonresult from avocado.core.plugins import jsonresult
from avocado.core import job from avocado.core import job
......
...@@ -5,13 +5,6 @@ import multiprocessing ...@@ -5,13 +5,6 @@ import multiprocessing
import tempfile import tempfile
import shutil import shutil
# simple magic for using scripts within a source tree
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..',
'..', '..')
basedir = os.path.abspath(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core import test from avocado.core import test
from avocado.core import exceptions from avocado.core import exceptions
from avocado.core import loader from avocado.core import loader
......
...@@ -2,12 +2,6 @@ import sys ...@@ -2,12 +2,6 @@ import sys
import os import os
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core.plugins import plugin from avocado.core.plugins import plugin
......
...@@ -2,12 +2,6 @@ import os ...@@ -2,12 +2,6 @@ import os
import sys import sys
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core.restclient import response from avocado.core.restclient import response
......
...@@ -7,12 +7,6 @@ if sys.version_info[:2] == (2, 6): ...@@ -7,12 +7,6 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core import settings from avocado.core import settings
example_1 = """[foo] example_1 = """[foo]
......
...@@ -8,12 +8,6 @@ if sys.version_info[:2] == (2, 6): ...@@ -8,12 +8,6 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core import sysinfo from avocado.core import sysinfo
......
...@@ -8,12 +8,6 @@ if sys.version_info[:2] == (2, 6): ...@@ -8,12 +8,6 @@ if sys.version_info[:2] == (2, 6):
else: else:
import unittest import unittest
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.core import test from avocado.core import test
from avocado.utils import script from avocado.utils import script
......
...@@ -2,12 +2,6 @@ import unittest ...@@ -2,12 +2,6 @@ import unittest
import os import os
import sys import sys
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import linux_modules from avocado.utils import linux_modules
......
...@@ -2,12 +2,6 @@ import unittest ...@@ -2,12 +2,6 @@ import unittest
import os import os
import sys import sys
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado.utils import output from avocado.utils import output
......
...@@ -6,12 +6,6 @@ from xml.dom import minidom ...@@ -6,12 +6,6 @@ from xml.dom import minidom
import tempfile import tempfile
import shutil import shutil
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
basedir = os.path.dirname(basedir)
if os.path.isdir(os.path.join(basedir, 'avocado')):
sys.path.insert(0, basedir)
from avocado import Test from avocado import Test
from avocado.core.plugins import xunit from avocado.core.plugins import xunit
from avocado.core import job from avocado.core import job
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册