File: test_main.py

package info (click to toggle)
snimpy 1.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 584 kB
  • sloc: python: 4,141; makefile: 21
file content (43 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import tempfile
import code  # noqa: F401
import platform
from snimpy.main import interact
from multiprocessing import Process
import agent
import unittest
import unittest.mock as mock


class TestMain(unittest.TestCase):

    """Test the main shell"""

    @classmethod
    def setUpClass(cls):
        cls.agent = agent.TestAgent()

    @classmethod
    def tearDownClass(cls):
        cls.agent.terminate()

    @unittest.skipIf(platform.python_implementation() == "PyPy",
                     "setupterm seems unreliable with Pypy")
    def test_loadfile(self):
        script = tempfile.NamedTemporaryFile(delete=False)
        try:
            script.write("""
load("IF-MIB")
m = M(host="127.0.0.1:{}",
      community="public",
      version=2)
assert(m.ifDescr[1] == "lo")
""".format(self.agent.port).encode("ascii"))
            script.close()
            with mock.patch("code.InteractiveInterpreter.write"):
                p = Process(target=interact, args=((script.name,),))
                p.start()
                p.join()
                self.assertEqual(p.exitcode, 0)
        finally:
            os.unlink(script.name)