예제 #1
0
    def test_error(self):
        with tdir():
            with self.assertRaises(TypeError) as m:
                tdir.fill('.', foo=3)
        assert m.exception.args[0].startswith('Do not understand type')

        with self.assertRaises(TypeError) as m:
            with tdir(None):
                pass
        assert m.exception.args[0].startswith('Do not understand type')
예제 #2
0
    def test_big(self):
        items = {
            'foo': {
                '__init__.py': 'TEST = 32\n',
                'toast.py': 'from . import TEST as TOAST\n',
            },
            'bar': {
                '__init__.py': 'import foo\nTEST = foo.TEST - 9\n',
                'toast.py': 'from . import TEST as TOAST\n',
            },
            'bang.py': 'TEST = 5\n',
            'data': ['a', 'b', 'c'],
        }

        with tdir(**items) as td:
            sys_path = sys.path[:]
            sys.path.insert(0, str(td))

            try:
                import bang
                import foo.toast
                import bar.toast

            finally:
                sys.path[:] = sys_path

            assert bang.TEST == 5
            assert foo.toast.TOAST == 32
            assert bar.toast.TOAST == 23
            for i in 'abc':
                assert (td / 'data' / i).read_text() == i + '\n'

        with tdir(items) as td:
            sys_path = sys.path[:]
            sys.path.insert(0, str(td))

            try:
                import bang
                import foo.toast
                import bar.toast

            finally:
                sys.path[:] = sys_path

            assert bang.TEST == 5
            assert foo.toast.TOAST == 32
            assert bar.toast.TOAST == 23
            for i in 'abc':
                assert (td / 'data' / i).read_text() == i + '\n'
예제 #3
0
    def test_usedir(self):
        cwd = os.getcwd()
        os.mkdir('one')

        with tdir():
            Path('one.txt').write_text('ONE')
            assert os.getcwd() != os.path.join(cwd, 'one')

        assert not Path('one/one.txt').exists()

        with tdir(use_dir='one'):
            Path('one.txt').write_text('ONE')
            assert os.getcwd() == os.path.join(cwd, 'one')

        assert Path('one/one.txt').read_text() == 'ONE'
예제 #4
0
    def test_simple(self):
        with tdir('setup.py', 'README') as td:
            cl = ChangeLog(td, '0.2.1', None, safer.printer, 'one', False)
            cl.new()

            actual = (td / 'CHANGELOG').read_text().splitlines()
            expected = ['## v0.2.1', '', '* one']
            assert expected[0].startswith(expected[0])
            assert actual[1:] == expected[1:]

            cl = ChangeLog(td, '0.2.1', None, safer.printer, 'two', False)

            with self.assertRaises(ValueError) as m:
                cl.new()
            assert m.exception.args[0].endswith('already exists')

            cl.update('0.3.0')
            actual = (td / 'CHANGELOG').read_text().splitlines()
            expected = [
                '## v0.3.0',
                '',
                '* two',
                '',
                '## v0.2.1',
                '',
                '* one',
            ]
            assert len(expected) == len(actual)
            for e, a in zip(expected, actual):
                if e.startswith('##'):
                    assert a.startswith(e)
                else:
                    assert a == e
예제 #5
0
 def test_in_python(self):
     with tdir(
             'setup.py',
             'README',
             'change.txt',
             sub={
                 'bar': 'one',
                 'foo.py': '__version__ = "0.1.2"'
             },
     ) as td:
         vf = version_file.VersionFile(td, None)
         assert vf.version == '0.1.2'
         assert vf.file.name == 'foo.py'
예제 #6
0
 def test_simple(self):
     with tdir(
             'setup.py',
             'README',
             'change.txt',
             sub={
                 'bar': 'one',
                 'VERSION': '0.1.2'
             },
     ) as td:
         vf = version_file.VersionFile(td, None)
         print('??', vf.version, vf.file)
         assert vf.version == '0.1.2'
         assert vf.file.name == 'VERSION'
예제 #7
0
    async def test_bash(self):
        with tdir({'test.sh': 'echo HELLO\npwd\n'}):
            await CastRecorder('test.sh').record_to('test.cast')
            Cast.read('test.cast').write('/code/scripta/test/test.cast')

            actual = [i.chars for i in Cast.read('test.cast').lines]
            expected = [
                constants.CONTROL_L,
                BASH_PS[0],
                '3',
                constants.BACKSPACE,
                'e',
                'c',
                'h',
                'o',
                ' ',
                'N',
                constants.BACKSPACE,
                'H',
                'E',
                'l',
                constants.BACKSPACE,
                'L',
                'L',
                'O',
                '\r\n',
                'HELLO\r\n',
                BASH_PS[0],
                'p',
                'w',
                'd',
                '\r\n',
                os.getcwd() + '\r\n',
                BASH_PS[0],
            ]
            if actual != expected:
                print(*actual, sep='\n')
            assert actual == expected
예제 #8
0
 def test_dict(self):
     with tdir(one='ONE', two='TWO') as td:
         assert sorted(i.name for i in td.iterdir()) == ['one', 'two']
         for i in ('one', 'two'):
             assert (td / i).read_text() == i.upper() + '\n'
예제 #9
0
    def test_save(self):
        with tdir(save=True) as td:
            Path('one.txt').write_text('ONE')

        assert Path(os.path.join(td, 'one.txt')).read_text() == 'ONE'
        shutil.rmtree(td)
예제 #10
0
 async def test_record_python(self):
     with tdir({'test.py': TEST_PY}):
         await CastRecorder('test.py').record_to('test.cast')
         actual = [i.chars for i in Cast.read('test.cast').lines]
         expected = [
             '\x1b[H\x1b[2J',
             '>>> ',
             '\r\n',
             'p',
             'r',
             'i',
             'n',
             't',
             '9',
             constants.BACKSPACE,
             '(',
             "'",
             'h',
             'e',
             'l',
             'l',
             'o',
             "'",
             '0',
             constants.BACKSPACE,
             ')',
             '\r\n',
             'hello\r\n',
             '>>> ',
             'i',
             'm',
             'p',
             'o',
             'r',
             'T',
             constants.BACKSPACE,
             't',
             ' ',
             'o',
             's',
             '\r\n',
             '>>> ',
             'O',
             constants.BACKSPACE,
             'o',
             's',
             '.',
             'g',
             'e',
             't',
             'c',
             's',
             constants.BACKSPACE,
             'w',
             'd',
             '(',
             ')',
             '\r\n',
             "'%s'\r\n" % os.getcwd(),
             '>>> ',
         ]
         if actual != expected:
             print(*actual, sep='\n')
         assert actual == expected
예제 #11
0
 def test_path2(self):
     path = Path(__file__)
     with tdir(foo=path):
         expected = path.read_text()
         actual = Path('foo').read_text()
         assert expected == actual
예제 #12
0
 def test_path1(self):
     path = Path(__file__)
     with tdir(path):
         expected = path.read_text()
         actual = Path(path.name).read_text()
         assert expected == actual
예제 #13
0
 def test_list(self):
     with tdir(sub=['one', 'two']) as td:
         sub = td / 'sub'
         assert sorted(i.name for i in sub.iterdir()) == ['one', 'two']
         for i in ('one', 'two'):
             assert (sub / i).read_text() == i + '\n'
예제 #14
0
 def test_binary(self):
     with tdir(one=b'ONE', two=bytearray(b'TWO')) as td:
         assert sorted(i.name for i in td.iterdir()) == ['one', 'two']
         for i in ('one', 'two'):
             assert (td / i).read_bytes() == i.upper().encode()
예제 #15
0
 def test_simple(self):
     with tdir('a', 'b', {'c': 'c'}, chdir=False) as td:
         assert sorted(i.name for i in td.iterdir()) == ['a', 'b', 'c']
         for i in 'abc':
             assert (td / i).read_text() == i + '\n'
             assert not Path(i).exists()
예제 #16
0
 def test_simple_cwd(self):
     with tdir('a', 'b', 'c') as td:
         assert sorted(i.name for i in td.iterdir()) == ['a', 'b', 'c']
         for i in 'abc':
             assert Path(i).read_text() == i + '\n'
예제 #17
0
 async def NO_test_scripta(self):
     with tdir():
         await scripta.scripta()