示例#1
0
    def test_cleanup_kills_backgrounded_processes_and_rmdirs(self):
        sourcetree = SourceTree()
        sourcetree.run_command(
            'python -c"import time; time.sleep(5)" & #runserver',
            cwd=sourcetree.tempdir)
        assert len(sourcetree.processes) == 1
        sourcetree_pid = sourcetree.processes[0].pid
        pids = subprocess.check_output('pgrep -f time.sleep',
                                       shell=True).decode('utf8').split()
        print('sourcetree_pid', sourcetree_pid)
        print('pids', pids)
        sids = []
        for pid in reversed(pids):
            print('checking', pid)
            cmd = 'ps -o sid --no-header -p %s' % (pid, )
            print(cmd)
            try:
                sid = subprocess.check_output(cmd, shell=True)
                print('sid', sid)
                sids.append(sid)
                assert sourcetree_pid == int(sid)
            except subprocess.CalledProcessError:
                pass
        assert sids

        sourcetree.cleanup()
        assert 'time.sleep' not in subprocess.check_output(
            'ps auxf', shell=True).decode('utf8')
示例#2
0
    def __init__(self,
                 parent,
                 id,
                 title,
                 pos=wx.DefaultPosition,
                 size=(1280, 720),
                 style=wx.DEFAULT_FRAME_STYLE):
        wx.Frame.__init__(self, parent, id, title, pos, size, style)
        self._mgr = aui.AuiManager(self)

        # create controls
        self.srcview = srcview = SourceTree(self, size=(200, 400))
        self.imgview = imgview = ImageView(self, size=(800, 600))

        # add the panes to the manger
        self._mgr.AddPane(srcview, wx.LEFT, "source view")
        self._mgr.AddPane(imgview, wx.CENTER)

        # tell the manager to 'commit' all the changes just made
        self._mgr.Update()

        # set menubar
        mainmenubar = MainMenuBar(self)
        mainmenubar.Append(imgview.imgmenu, "&ImageView")
        self.SetMenuBar(mainmenubar)

        # set statusbar
        self.CreateStatusBar(2)
        self.OnPanelChanged()

        self.Bind(wx.EVT_CLOSE, self.OnQuit)
        pub.subscribe(self.OnPanelChanged, PT.TPC_IMG_SEL_CHANGED)
        pub.subscribe(self.OnPanelSizeChanged, PT.TPC_IMG_SIZE_CHANGED)

        self.Show(True)
示例#3
0
 def test_raises_on_errors(self):
     sourcetree = SourceTree()
     with self.assertRaises(Exception):
         sourcetree.run_command('synt!tax error', cwd=sourcetree.tempdir)
     sourcetree.run_command('synt!tax error',
                            cwd=sourcetree.tempdir,
                            ignore_errors=True)
示例#4
0
 def setUp(self):
     self.sourcetree = SourceTree()
     self.sourcetree.get_local_repo_path = lambda c: os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'testrepo'))
     self.sourcetree.start_with_checkout(17)
     self.sourcetree.run_command('git checkout test-start')
     self.sourcetree.run_command('git reset')
示例#5
0
 def setUp(self):
     self.sourcetree = SourceTree()
     self.tempdir = self.sourcetree.tempdir
     self.processes = []
     self.pos = 0
     self.dev_server_running = False
     self.current_server_cd = None
示例#6
0
    def test_running_interactive_command(self):
        sourcetree = SourceTree()

        command = "python3 -c \"print('input please?'); a = input();print('OK' if a=='yes' else 'NO')\""
        output = sourcetree.run_command(command, user_input='no')
        assert 'NO' in output
        output = sourcetree.run_command(command, user_input='yes')
        assert 'OK' in output
示例#7
0
 def test_checks_out_repo_current_chapter_as_master(self):
     sourcetree = SourceTree()
     sourcetree.get_local_repo_path = lambda c: os.path.abspath(
         os.path.join(os.path.dirname(__file__), 'testrepo'))
     sourcetree.start_with_checkout(21)
     remotes = sourcetree.run_command('git remote').split()
     assert remotes == ['repo']
     branch = sourcetree.run_command('git branch').strip()
     assert branch == '* master'
     diff = sourcetree.run_command('git diff repo/chapter_20').strip()
     assert diff == ''
示例#8
0
 def test_special_cases_fab_deploy(self, mock_subprocess):
     mock_subprocess.Popen.return_value.returncode = 0
     mock_subprocess.Popen.return_value.communicate.return_value = 'a', 'b'
     sourcetree = SourceTree()
     sourcetree.run_command('fab deploy:[email protected]')
     expected = (
         'cd deploy_tools &&'
         ' fab -D -i'
         ' ~/Dropbox/Book/.vagrant/machines/default/virtualbox/private_key'
         ' deploy:[email protected]'
     )
     assert mock_subprocess.Popen.call_args[0][0] == expected
示例#9
0
 def test_special_cases_wget_bootstrap(self):
     sourcetree = SourceTree()
     sourcetree.run_command('mkdir superlists', cwd=sourcetree.tempdir)
     with patch('sourcetree.subprocess') as mock_subprocess:
         mock_subprocess.Popen.return_value.communicate.return_value = (
             'bla bla', None)
         sourcetree.run_command(BOOTSTRAP_WGET)
         assert not mock_subprocess.Popen.called
     assert os.path.exists(
         os.path.join(sourcetree.tempdir, 'superlists', 'bootstrap.zip'))
     diff = sourcetree.run_command('diff %s bootstrap.zip' % (os.path.join(
         os.path.dirname(__file__), '..', 'downloads', 'bootstrap.zip')))
     assert diff == ''
示例#10
0
 def test_doesnt_raise_for_some_things_where_a_return_code_is_ok(self):
     sourcetree = SourceTree()
     sourcetree.run_command('diff foo bar', cwd=sourcetree.tempdir)
     sourcetree.run_command('python test.py', cwd=sourcetree.tempdir)
示例#11
0
 def test_environment_variables(self):
     sourcetree = SourceTree()
     os.environ['TEHFOO'] = 'baz'
     output = sourcetree.run_command('echo $TEHFOO', cwd=sourcetree.tempdir)
     assert output.strip() == 'baz'
示例#12
0
 def test_default_directory_is_superlists(self):
     sourcetree = SourceTree()
     os.makedirs(os.path.join(sourcetree.tempdir, 'superlists'))
     sourcetree.run_command('touch foo')
     assert os.path.exists(
         os.path.join(sourcetree.tempdir, 'superlists', 'foo'))
示例#13
0
 def test_running_simple_command(self):
     sourcetree = SourceTree()
     sourcetree.run_command('touch foo', cwd=sourcetree.tempdir)
     assert os.path.exists(os.path.join(sourcetree.tempdir, 'foo'))
示例#14
0
 def test_get_local_repo_path(self):
     sourcetree = SourceTree()
     assert sourcetree.get_local_repo_path(12) == os.path.abspath(
         os.path.join(os.path.dirname(__file__),
                      '../source/chapter_12/superlists'))
示例#15
0
 def test_get_contents(self):
     sourcetree = SourceTree()
     os.makedirs(sourcetree.tempdir + '/superlists')
     with open(sourcetree.tempdir + '/superlists/foo.txt', 'w') as f:
         f.write('bla bla')
     assert sourcetree.get_contents('foo.txt') == 'bla bla'
示例#16
0
 def test_default_directory_is_tempdir(self):
     sourcetree = SourceTree()
     sourcetree.run_command('touch foo')
     assert os.path.exists(os.path.join(sourcetree.tempdir, 'foo'))
示例#17
0
 def test_returns_output(self):
     sourcetree = SourceTree()
     output = sourcetree.run_command('echo hello', cwd=sourcetree.tempdir)
     assert output == 'hello\n'
 def test_environment_variables(self):
     sourcetree = SourceTree()
     output = sourcetree.run_command('echo $PIP_DOWNLOAD_CACHE', cwd=sourcetree.tempdir)
     assert output == '/home/harry/.pip-download-cache\n'