提交 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.
import os
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
......
......@@ -7,17 +7,15 @@ if sys.version_info[:2] == (2, 6):
else:
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 job_id
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):
def test_unknown_command(self):
......
......@@ -11,14 +11,13 @@ if sys.version_info[:2] == (2, 6):
else:
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.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
true
......
......@@ -4,16 +4,15 @@ import unittest
import tempfile
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.utils import process
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
echo "Avocado Version: $AVOCADO_VERSION"
echo "Avocado Test basedir: $AVOCADO_TEST_BASEDIR"
......
......@@ -4,13 +4,11 @@ import unittest
import shutil
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.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):
......
......@@ -12,17 +12,16 @@ if sys.version_info[:2] == (2, 6):
else:
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 process
from avocado.utils import script
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
import signal
import time
......
......@@ -9,14 +9,13 @@ if sys.version_info[:2] == (2, 6):
else:
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.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
sleep 2
......
......@@ -6,13 +6,11 @@ import sqlite3
import tempfile
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.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):
......
......@@ -8,14 +8,13 @@ if sys.version_info[:2] == (2, 6):
else:
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.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
from avocado import Test
......
......@@ -10,13 +10,12 @@ if sys.version_info[:2] == (2, 6):
else:
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.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
/distro/mint:init => systemv@examples/mux-environment.yaml:/distro/mint
......
......@@ -11,16 +11,14 @@ if sys.version_info[:2] == (2, 6):
else:
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.core.output import TermSupport
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
class OutputTest(unittest.TestCase):
def setUp(self):
......
......@@ -8,14 +8,13 @@ if sys.version_info[:2] == (2, 6):
else:
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.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
echo "Hello, avocado!"
......
......@@ -6,13 +6,11 @@ if sys.version_info[:2] == (2, 6):
else:
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.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):
......
......@@ -8,13 +8,11 @@ if sys.version_info[:2] == (2, 6):
else:
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.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):
......
......@@ -6,14 +6,13 @@ if sys.version_info[:2] == (2, 6):
else:
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.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
from unittest import main
......
......@@ -9,12 +9,6 @@ if sys.version_info[:2] == (2, 6):
else:
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
FAKE_VMSTAT_CONTENTS = """#!/usr/bin/python
......
......@@ -4,14 +4,13 @@ import unittest
import tempfile
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.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
touch %s
......
......@@ -5,12 +5,6 @@ import sys
import shutil
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 crypto
from avocado.utils import data_factory
......
......@@ -2,12 +2,6 @@ import unittest
import os
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
......
......@@ -6,13 +6,6 @@ import tempfile
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
......
......@@ -5,14 +5,6 @@ import unittest
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
......
......@@ -2,13 +2,6 @@ import os
import sys
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
......
......@@ -6,12 +6,6 @@ import argparse
import tempfile
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.core.plugins import jsonresult
from avocado.core import job
......
......@@ -5,13 +5,6 @@ import multiprocessing
import tempfile
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 exceptions
from avocado.core import loader
......
......@@ -2,12 +2,6 @@ import sys
import os
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
......
......@@ -2,12 +2,6 @@ import os
import sys
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
......
......@@ -7,12 +7,6 @@ if sys.version_info[:2] == (2, 6):
else:
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
example_1 = """[foo]
......
......@@ -8,12 +8,6 @@ if sys.version_info[:2] == (2, 6):
else:
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
......
......@@ -8,12 +8,6 @@ if sys.version_info[:2] == (2, 6):
else:
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.utils import script
......
......@@ -2,12 +2,6 @@ import unittest
import os
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
......
......@@ -2,12 +2,6 @@ import unittest
import os
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
......
......@@ -6,12 +6,6 @@ from xml.dom import minidom
import tempfile
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.core.plugins import xunit
from avocado.core import job
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册