Esempio n. 1
0
 def test_does_not_contain_files(self):
     tempdir = self.mkdtemp()
     self.touch(os.path.join(tempdir, 'foo'))
     mismatch = DirContains(['bar', 'foo']).match(tempdir)
     self.assertThat(
         Equals(['bar', 'foo']).match(['foo']).describe(),
         Equals(mismatch.describe()))
Esempio n. 2
0
 def test_does_not_contain_files(self):
     tempdir = self.mkdtemp()
     self.touch(os.path.join(tempdir, 'foo'))
     mismatch = DirContains(['bar', 'foo']).match(tempdir)
     self.assertThat(
         Equals(['bar', 'foo']).match(['foo']).describe(),
         Equals(mismatch.describe()))
Esempio n. 3
0
 def test_out_of_order(self):
     # If a file or a subdirectory is listed before its parent directory,
     # that doesn't matter.  We'll create the directory first.
     path = self.useFixture(TempDir()).path
     make_tree(path, ['a/b/', 'a/'])
     self.assertThat(path, DirContains(['a']))
     self.assertThat(os.path.join(path, 'a'), DirContains(['b']))
     self.assertThat(os.path.join(path, 'a', 'b'), DirExists())
Esempio n. 4
0
 def test_out_of_order(self):
     # If a file or a subdirectory is listed before its parent directory,
     # that doesn't matter.  We'll create the directory first.
     fixture = FileTree(['a/b/', 'a/'])
     with fixture:
         path = fixture.path
         self.assertThat(path, DirContains(['a']))
         self.assertThat(os.path.join(path, 'a'), DirContains(['b']))
         self.assertThat(os.path.join(path, 'a', 'b'), DirExists())
Esempio n. 5
0
 def test_creates_parent_directories(self):
     # If the parents of a file or directory don't exist, they get created
     # too.
     path = self.useFixture(TempDir()).path
     create_normal_shape(path, [('a/b/', None), ('c/d.txt', 'text')])
     self.assertThat(path, DirContains(['a', 'c']))
     self.assertThat(os.path.join(path, 'a'), DirContains('b'))
     self.assertThat(os.path.join(path, 'a', 'b'), DirExists())
     self.assertThat(os.path.join(path, 'c'), DirExists())
     self.assertThat(os.path.join(path, 'c', 'd.txt'), FileContains('text'))
    def test_save_on_switch_tab_and_not_delete_if_topsite(self):
        previous = self.main_window.get_current_webview().url

        # switching away from tab should save a capture
        self.open_new_tab(open_tabs_view=True)
        self.assertThat(self.captures_dir,
                        DirContains([self.capture_file(previous)]))

        # closing the captured tab should not delete the capture since it is
        # now part of the top sites (being the only one we opened so far)
        self.close_tab(0)
        time.sleep(0.5)  # wait for file system to settle
        self.assertThat(self.captures_dir,
                        DirContains([self.capture_file(previous)]))
Esempio n. 7
0
 def test_creates_directories(self):
     # When given directory specifications, it creates those directories.
     path = self.useFixture(TempDir()).path
     create_normal_shape(path, [('a/', None), ('b/', None)])
     self.assertThat(path, DirContains(['a', 'b']))
     self.assertThat(os.path.join(path, 'a'), DirExists())
     self.assertThat(os.path.join(path, 'b'), DirExists())
Esempio n. 8
0
 def test_creates_files(self):
     # When given a list of file specifications, it creates those files
     # underneath the temporary directory.
     path = self.useFixture(TempDir()).path
     create_normal_shape(path, [('a', 'foo'), ('b', 'bar')])
     self.assertThat(path, DirContains(['a', 'b']))
     self.assertThat(os.path.join(path, 'a'), FileContains('foo'))
     self.assertThat(os.path.join(path, 'b'), FileContains('bar'))
    def populate_captures_dir(self, capture_names):
        # captures dir should not exist on fresh run
        self.assertThat(self.captures_dir, Not(DirExists()))

        # create some random files and ensure they get cleaned up
        os.mkdir(self.captures_dir)
        for capture_name in capture_names:
            open(path.join(self.captures_dir, capture_name), 'w').close()
        self.assertThat(self.captures_dir, DirContains(capture_names))
Esempio n. 10
0
    def test_delete_when_tab_closed_and_removed_from_topsites(self):
        previous = self.main_window.get_current_webview().url
        capture = self.capture_file(previous)
        new_tab_view = self.open_new_tab(open_tabs_view=True)
        self.close_tab(0)
        time.sleep(0.5)  # wait for file system to settle
        self.assertThat(self.captures_dir, DirContains([capture]))

        if not self.main_window.wide:
            new_tab_view = self.open_new_tab(open_tabs_view=True)
        self.remove_top_site(new_tab_view, previous)
        self.assertThat(lambda: self.file_in_dir(capture, self.captures_dir),
                        Eventually(Equals(False)))
 def test_sign_with_external_run_parts(self):
     self.enableRunParts(distribution_name=self.distro.name)
     with open(
             os.path.join(self.parts_directory, self.distro.name, "sign.d",
                          "10-sign"), "w") as f:
         f.write(
             dedent("""\
             #! /bin/sh
             touch "$OUTPUT_PATH"
             """))
         os.fchmod(f.fileno(), 0o755)
     self.openArchive("20060302.0120")
     self.tarfile.add_file("20060302.0120/list", "a list")
     self.tarfile.add_file("20060302.0120/foo.tar.gz", "a tarball")
     self.process()
     self.assertThat(os.path.join(self.getUpgraderPath(), "20060302.0120"),
                     DirContains(["list", "foo.tar.gz", "foo.tar.gz.gpg"]))
 def test_sign_with_external_run_parts(self):
     self.enableRunParts(distribution_name=self.distro.name)
     with open(
             os.path.join(self.parts_directory, self.distro.name, "sign.d",
                          "10-sign"), "w") as f:
         f.write(
             dedent("""\
             #! /bin/sh
             touch "$OUTPUT_PATH"
             """))
         os.fchmod(f.fileno(), 0o755)
     self.openArchive()
     self.addFile("images/list", "a list")
     self.addFile("images/SHA256SUMS", "a checksum")
     self.process()
     self.assertThat(self.getInstallerPath("images"),
                     DirContains(["list", "SHA256SUMS", "SHA256SUMS.gpg"]))
Esempio n. 13
0
    def test_cleanup_previews_on_startup(self):
        self.populate_history()

        # populate the captures dir with correct thumbnail names for all
        # the sites in history...
        history = ["http://en.wikipedia.org/wiki/" + c for c in self.countries]
        history = [self.capture_file(url) for url in history]

        # ...plus some other files to verify possible corner cases
        other_url = self.capture_file("http://google.com/")
        not_hash = "not_a_preview.jpg"
        not_image = "not_an_image.xxx"
        self.populate_captures_dir(history + [other_url, not_hash, not_image])

        self.launch_app()
        time.sleep(1)  # wait for file system to settle

        # verify that non-image files and top 10 sites are left alone,
        # everything else is cleaned up
        topsites = history[0:10]
        current_tab = self.capture_file(self.url)
        self.assertThat(self.captures_dir,
                        DirContains(topsites + [not_image, current_tab]))
Esempio n. 14
0
 def test_not_exists(self):
     doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
     mismatch = DirContains([]).match(doesntexist)
     self.assertThat(PathExists().match(doesntexist).describe(),
                     Equals(mismatch.describe()))
Esempio n. 15
0
 def test_empty(self):
     tempdir = self.mkdtemp()
     self.assertThat(tempdir, DirContains([]))
Esempio n. 16
0
 def test_empty(self):
     tempdir = self.useFixture(TempDir()).path
     create_normal_shape(tempdir, [])
     self.assertThat(tempdir, DirContains([]))
Esempio n. 17
0
 def test_leaves_nothing_behind_on_error(self):
     dirname = self.make_dir()
     filename = os.path.join(dirname, "does-not-exist")
     self.assertRaises(FileNotFoundError, atomic_delete, filename)
     self.assertThat(dirname, DirContains([]))
Esempio n. 18
0
 def test_contains_files(self):
     tempdir = self.mkdtemp()
     self.touch(os.path.join(tempdir, 'foo'))
     self.touch(os.path.join(tempdir, 'bar'))
     self.assertThat(tempdir, DirContains(['bar', 'foo']))
Esempio n. 19
0
 def test_matcher(self):
     tempdir = self.mkdtemp()
     self.touch(os.path.join(tempdir, 'foo'))
     self.touch(os.path.join(tempdir, 'bar'))
     self.assertThat(tempdir, DirContains(matcher=Contains('bar')))
Esempio n. 20
0
 def test_tree(self):
     """The install_resources function creates the filesystem structure."""
     install_resources(root_dir=Path(self.root_dir.path))
     paths = ['basic-auth', 'bin', 'static', 'reprepro', 'sign-passphrase']
     self.assertThat(
         self.root_dir.join('srv/archive-auth-mirror'), DirContains(paths))
Esempio n. 21
0
 def test_not_exists(self):
     doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
     mismatch = DirContains([]).match(doesntexist)
     self.assertThat(
         PathExists().match(doesntexist).describe(),
         Equals(mismatch.describe()))