File: test_commands.py

package info (click to toggle)
testpath 0.4.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 216 kB
  • sloc: python: 531; makefile: 160; sh: 2
file content (36 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (4)
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
import os
from subprocess import call
import unittest

from testpath.commands import *

class CommandsTests(unittest.TestCase):
    def test_assert_calls(self):
        initial_path = os.environ['PATH']        
        
        with assert_calls('foobar'):
            call(['foobar'])
        
        with self.assertRaises(AssertionError):
            with assert_calls('foo'):
                pass
        
        # The context manager should clean up $PATH again
        self.assertEqual(os.environ['PATH'], initial_path)
    
    def test_assert_calls_with_args(self):
        with assert_calls('foo', ['bar', 'baz']):
            call(['foo', 'bar', 'baz'])
        
        with self.assertRaises(AssertionError):
            with assert_calls('cheese', ['crackers']):
                call(['cheese', 'biscuits'])
                call(['cheese', 'wine'])

    def test_assert_calls_twice(self):
        with assert_calls('git'):
            call(['git'])

        with self.assertRaises(AssertionError):
            with assert_calls('git'):
                pass