コード例 #1
0
    def test_archive_directory_exists(self, capfd):
        out, _ = run_ofSM('archive -p mockProject', capfd=capfd)
        assert ('Metadata file metadata.json does not exist yet. Creating'
                in out)

        out, _ = run_ofSM('archive -v -p mockProject -n someName', capfd=capfd)
        assert ('Directory mockProject_archive already exists. Continuing.'
                in out)
コード例 #2
0
    def test_checkout_no_entry(self, capfd):
        # Create metadata file
        run_ofSM("record -p mockProject")

        # Try to checkout non-existing entry
        out, err = run_ofSM("checkout -p mockProject -n some_name", capfd=capfd, desired_exit_status=1)
        assert "Loaded json data from metadata.json" in out
        assert "Snapshot entry some_name does not exist." in err
コード例 #3
0
    def test_archive_skipping(self, capfd):
        out, _ = run_ofSM('archive -p mockProject', capfd=capfd)
        assert ('Metadata file metadata.json does not exist yet. Creating'
                in out)

        # Do it again to provoke skipping files
        out, _ = run_ofSM('archive -p mockProject', capfd=capfd)
        assert  ' already exists. Skipping ...' in out
コード例 #4
0
 def test_record_default_p_dir(self):
     currentdir = os.getcwd()
     os.chdir('mockProject')
     run_ofSM('record')
     std = load_json_file(os.path.join(REPLAY_DIR, 'md_record.json'))
     test = load_json_file(os.path.join(currentdir, 'mockProject',
                                     'metadata.json'))
     assert test == std
コード例 #5
0
    def test_checkout_head_detached(self, capfd):
        # Create metadata file
        run_ofSM("record -p mockProject")

        # Check it out again, assert that there's no detached HEAD
        out, err = run_ofSM("checkout -v -p mockProject", capfd=capfd)
        assert "You are in 'detached HEAD' state" not in out
        assert "You are in 'detached HEAD' state" not in err
コード例 #6
0
    def test_checkout_default(self, capfd):
        # Create metadata file
        run_ofSM("record -p mockProject")

        # Do a default checkout
        _, err = run_ofSM("checkout -p mockProject", capfd=capfd)
        assert "git repo could not be validated successfully." not in err
        assert "Correct code state cannot be guaranteed!" in err
        assert "ofxNonGitAddon" in err
コード例 #7
0
    def test_checkout_addon_invalid(self, capfd):
        # Create metadata file
        run_ofSM("record -p mockProject")

        # Remove an addon's .git directory to make checkout validation fail
        shutil.rmtree(os.path.join("mockOF", "addons", "ofxSomeAddon", ".git"))
        # Do a checkout
        _, err = run_ofSM("checkout -p mockProject", capfd=capfd, desired_exit_status=1)
        assert "ofxSomeAddon git repo could not be validated successfully." in err
コード例 #8
0
    def test_archive_named_snapshot(self, capfd):
        # First, create a metadata file
        out, _ = run_ofSM('record -p mockProject', capfd=capfd)
        assert 'metadata.json does not exist yet. Creating' in out

        # Now, create a named snapshot
        out, _ = run_ofSM('archive -p mockProject -n someName', capfd=capfd)
        assert ('Metadata file metadata.json does not exist yet. Creating'
                not in out)
        assert 'Entry someName does not exist yet. Creating...' in out
コード例 #9
0
    def test_archive_description(self, capfd):
        # First, create an entry with a description
        out, _ = run_ofSM('record -p mockProject -d "my description"',
                          capfd=capfd)
        assert 'metadata.json does not exist yet. Creating' in out

        # Now, archive the "latest" entry
        out, _ = run_ofSM('archive -p mockProject', capfd=capfd)
        assert 'Writing description file' in out
        with open(os.path.join('mockProject', 'mockProject_archive',
                               'mockProject_latest_description.txt'),
                  'r') as descr:
            assert descr.readline() == "my description"
コード例 #10
0
    def test_record_update(self):
        # copy snapshot-1 metadata file over to mockProject
        shutil.copyfile(os.path.join(REPLAY_DIR, 'md_record_snapshot-1.json'),
                        os.path.join('mockProject', 'metadata.json'))
        # this has to bail because -u was not given
        run_ofSM('record -p mockProject -n snapshot-1', desired_exit_status=1)
        # this has to work
        run_ofSM('record -u -p mockProject -n snapshot-1')

        std = load_json_file(os.path.join(REPLAY_DIR,
                                          'md_record_snapshot-1.json'))
        test = load_json_file(os.path.join('mockProject', 'metadata.json'))
        assert test == std
コード例 #11
0
 def test_record_no_OF_location(self, capfd):
     fobj = open(os.path.join(os.getcwd(), 'mockProject', 'config.make'),
                 'w')
     fobj.close()
     _, err = run_ofSM('record -p mockProject', capfd=capfd,
                       desired_exit_status=1)
     assert 'Did not find OF location in config.make in' in err
コード例 #12
0
    def test_list(self, capfd):
        run_ofSM('record -p mockProject')
        out, _ = run_ofSM('list -p mockProject', capfd=capfd)
        assert 'Loaded json data' in out
        assert 'Available snapshots:' in out
        assert 'latest' in out

        out, _ = run_ofSM('list -p mockProject -n latest', capfd=capfd)
        assert 'Loaded json data from' in out
        assert 'Selecting snapshot latest' in out
        assert 'Detailed info for snapshot latest:' in out
        assert 'path: ../mockOF' in out

        out, err = run_ofSM('list -p mockProject -n notexist', capfd=capfd,
                            desired_exit_status=1)
        assert 'Snapshot entry notexist does not exist.' in err
コード例 #13
0
    def test_checkout_no_nongit(self, capfd):
        # Remove non-git addon from addons.make
        with open(os.path.join("mockProject", "addons.make"), "r") as fobj:
            lines = fobj.readlines()
        with open(os.path.join("mockProject", "addons.make"), "w") as fobj:
            for line in lines:
                if line.rstrip() != "ofxNonGitAddon":
                    fobj.write(line)

        # Create metadata file
        run_ofSM("record -p mockProject")

        # Do a default checkout
        _, err = run_ofSM("checkout -p mockProject", capfd=capfd)
        assert "git repo could not be validated successfully." not in err
        assert "Correct code state cannot be guaranteed!" not in err
        assert "ofxNonGitAddon" not in err
コード例 #14
0
 def test_record_named(self, capfd):
     out, err = run_ofSM('record -p mockProject -n snapshot-1', capfd=capfd)
     assert 'DEBUG' not in out
     assert 'DEBUG' not in err
     std = load_json_file(os.path.join(REPLAY_DIR,
                                       'md_record_snapshot-1.json'))
     test = load_json_file(os.path.join('mockProject', 'metadata.json'))
     assert test == std
コード例 #15
0
    def test_record_verbosity(self, capfd):
        out, _ = run_ofSM('record -v -p mockProject -n snapshot-1',
                          capfd=capfd)
        assert 'DEBUG' in out

        std = load_json_file(os.path.join(REPLAY_DIR,
                                          'md_record_snapshot-1.json'))
        test = load_json_file(os.path.join('mockProject', 'metadata.json'))
        assert test == std
コード例 #16
0
    def test_checkout_head_should_be_detached(self, capfd):
        # detach the head of OF
        os.chdir("mockOF")
        ret = subprocess.call(["git", "checkout", "HEAD^1"])
        assert ret == 0
        os.chdir("..")

        # Create metadata file
        run_ofSM("record -p mockProject")

        # reattach the head of OF
        os.chdir("mockOF")
        ret = subprocess.call(["git", "checkout", "master"])
        assert ret == 0
        _, _ = capfd.readouterr()
        os.chdir("..")

        # Check it out again, assert that there's a detached HEAD now
        _, err = run_ofSM("checkout -p mockProject", capfd=capfd)
        assert "You are in 'detached HEAD' state" in err
コード例 #17
0
 def test_archive_default(self, capfd):
     out, _ = run_ofSM('archive -p mockProject', capfd=capfd)
     assert ('Metadata file metadata.json does not exist yet. Creating'
             in out)
コード例 #18
0
 def test_list_description_detailed(self, capfd):
     run_ofSM('record -p mockProject -d "a text" -n dummy')
     out, _ = run_ofSM('list -p mockProject -n dummy', capfd=capfd)
     assert 'Detailed info for snapshot dummy:' in out
     assert 'Description: a text' in out
コード例 #19
0
 def test_list_description_named(self, capfd):
     run_ofSM('record -p mockProject -d "a text" -n dummy')
     out, _ = run_ofSM('list -p mockProject', capfd=capfd)
     assert 'dummy: a text' in out
コード例 #20
0
 def test_list_description_latest(self, capfd):
     run_ofSM('record -p mockProject -d "some description"')
     out, _ = run_ofSM('list -p mockProject', capfd=capfd)
     assert 'latest: some description' in out
コード例 #21
0
 def test_help(self, capfd):
     """Test if help text gets printed"""
     out, err = run_ofSM('--help', capfd=capfd)
     assert out.startswith('usage: ofStateManager.py [-h]')
     assert err == ''
コード例 #22
0
 def test_help_record(self, capfd):
     """Test if record help text gets printed"""
     out, err = run_ofSM('record -h', capfd=capfd)
     assert out.startswith('usage: ofStateManager.py record [-h]')
     assert err == ''
コード例 #23
0
 def test_record_no_addonsmake(self, capfd):
     os.remove(os.path.join(os.getcwd(), 'mockProject', 'addons.make'))
     out, _ = run_ofSM('record -v -p mockProject', capfd=capfd)
     assert 'No addons.make file found.' in out
コード例 #24
0
 def test_record(self):
     run_ofSM('record -p mockProject')
     std = load_json_file(os.path.join(REPLAY_DIR, 'md_record.json'))
     test = load_json_file(os.path.join('mockProject', 'metadata.json'))
     assert test == std
コード例 #25
0
 def test_record_addon_nonexistent(self, capfd):
     shutil.rmtree(os.path.join('mockOF', 'addons', 'ofxSomeAddon'))
     _, err = run_ofSM('record -p mockProject', capfd=capfd,
                       desired_exit_status=1)
     assert 'ofxSomeAddon does not exist at' in err
     assert err.endswith('Aborting\n')
コード例 #26
0
 def test_record_wrong_project(self, capfd):
     _, err = run_ofSM('record -p mockProjectWRONG', capfd=capfd,
                       desired_exit_status=1)
     # Do this because subprocess does not raise its child's exceptions
     assert 'Error: [Errno 2]' in err
コード例 #27
0
 def test_record_addon_invalid(self, capfd):
     open(os.path.join(os.getcwd(), 'mockOF', 'addons', 'ofxSomeAddon',
                     'untracked.txt'), 'w').close()
     _, err = run_ofSM('record -p mockProject', capfd=capfd,
                       desired_exit_status=1)
     assert 'Repository has untracked files' in err
コード例 #28
0
 def test_help_archive(self, capfd):
     """Test if archive help text gets printed"""
     out, err = run_ofSM('archive -h', capfd=capfd)
     assert out.startswith('usage: ofStateManager.py archive [-h]')
     assert err == ''
コード例 #29
0
 def test_record_description(self):
     run_ofSM('record -p mockProject -d "My Test description"')
     std = load_json_file(os.path.join(REPLAY_DIR,
                                       'md_record_description.json'))
     test = load_json_file(os.path.join('mockProject', 'metadata.json'))
     assert test == std
コード例 #30
0
 def test_record_empty_addons_make(self, capfd):
     fobj = open(os.path.join(os.getcwd(), 'mockProject', 'addons.make'),
                 'w')
     fobj.close()
     out, _ = run_ofSM('record -p mockProject', capfd=capfd)
     assert 'No addons found.' in out