Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code reformatting #201

Merged
merged 1 commit into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/test/scala/io/archivesunleashed/ArcTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed

import com.google.common.io.Resources
import io.archivesunleashed.matchbox.ExtractDate.DateComponent
import io.archivesunleashed.matchbox._
import org.apache.spark.{SparkConf, SparkContext}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfter, FunSuite}
import matchbox.ExtractDate.DateComponent
import matchbox._

@RunWith(classOf[JUnitRunner])
class ArcTest extends FunSuite with BeforeAndAfter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed

import com.google.common.io.Resources
Expand All @@ -22,7 +23,6 @@ import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfter, FunSuite}


@RunWith(classOf[JUnitRunner])
class ArchiveRecordTest extends FunSuite with BeforeAndAfter {
private val arcPath = Resources.getResource("arc/example.arc.gz").getPath
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/io/archivesunleashed/CountableRDDTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.archivesunleashed

import matchbox._
package io.archivesunleashed

import com.google.common.io.Resources
import io.archivesunleashed.matchbox._
import org.apache.spark.{SparkConf, SparkContext}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
Expand Down
92 changes: 45 additions & 47 deletions src/test/scala/io/archivesunleashed/RecordLoaderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,55 @@
* limitations under the License.
*/

package io.archivesunleashed
package io.archivesunleashed

import com.google.common.io.Resources
import org.apache.spark.{SparkConf, SparkContext}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfter, FunSuite}
import java.nio.file.{Files, Paths}
import com.google.common.io.Resources
import io.archivesunleashed.util.TweetUtils._
import org.apache.spark.{SparkConf, SparkContext}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfter, FunSuite}

import io.archivesunleashed.util.TweetUtils._
@RunWith(classOf[JUnitRunner])
class RecordLoaderTest extends FunSuite with BeforeAndAfter {
private val warcPath = Resources.getResource("warc/example.warc.gz").getPath
private val tweetPath = Resources.getResource("arc/tweetsTest.json").getPath
private val delTweetPath = Resources.getResource("arc/delTweetsTest.json").getPath
private val master = "local[4]"
private val appName = "example-spark"
private var sc: SparkContext = _

@RunWith(classOf[JUnitRunner])
class RecordLoaderTest extends FunSuite with BeforeAndAfter {
private val warcPath = Resources.getResource("warc/example.warc.gz").getPath
private val tweetPath = Resources.getResource("arc/tweetsTest.json").getPath
private val delTweetPath = Resources.getResource("arc/delTweetsTest.json").getPath
private val master = "local[4]"
private val appName = "example-spark"
private var sc: SparkContext = _
before {
val conf = new SparkConf()
.setMaster(master)
.setAppName(appName)
sc = new SparkContext(conf)
}

before {
val conf = new SparkConf()
.setMaster(master)
.setAppName(appName)
sc = new SparkContext(conf)
}
test("loads Warc") {
val base = RecordLoader.loadArchives(warcPath, sc)
.keepValidPages()
.map(x => x.getUrl)
.take(1)
assert(base(0) == "http://www.archive.org/")
}

test("loads Warc") {
val base = RecordLoader.loadArchives(warcPath, sc)
.keepValidPages()
.map(x => x.getUrl)
.take(1)
assert (base(0) == "http://www.archive.org/")
}
test("loads Tweets") {
val base = RecordLoader.loadTweets(tweetPath, sc)
.map(x => x.text())
.collect()
assert(base(0) == "some text")
assert(base(1) == "some more text")
}

test("loads Tweets") {
val base = RecordLoader.loadTweets(tweetPath, sc)
.map(x => x.text())
.collect()
assert (base(0) == "some text")
assert (base(1) == "some more text")
}
test("does not load deleted") {
val base = RecordLoader.loadTweets(delTweetPath, sc).collect()
assert(base.deep == Array().deep)
}

test("does not load deleted") {
val base = RecordLoader.loadTweets(delTweetPath, sc).collect()
assert (base.deep == Array().deep)
}

after {
if (sc != null) {
sc.stop()
}
}
}
after {
if (sc != null) {
sc.stop()
}
}
}
9 changes: 3 additions & 6 deletions src/test/scala/io/archivesunleashed/RecordRDDTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.archivesunleashed

import matchbox._
import matchbox.ExtractDate.DateComponent
import matchbox.ExtractDate.DateComponent.DateComponent
package io.archivesunleashed

import com.google.common.io.Resources
import io.archivesunleashed.matchbox.ExtractDate.DateComponent
import io.archivesunleashed.matchbox._
import org.apache.spark.{SparkConf, SparkContext}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfter, FunSuite}
import scala.util.matching.Regex

@RunWith(classOf[JUnitRunner])
class RecordRDDTest extends FunSuite with BeforeAndAfter {
Expand All @@ -35,7 +33,6 @@ class RecordRDDTest extends FunSuite with BeforeAndAfter {
private val appName = "example-spark"
private var sc: SparkContext = _


before {
val conf = new SparkConf()
.setMaster(master)
Expand Down
1 change: 1 addition & 0 deletions src/test/scala/io/archivesunleashed/WarcTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed

import com.google.common.io.Resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed.matchbox

import java.awt.image.BufferedImage
import java.io.ByteArrayOutputStream
import javax.imageio.ImageIO

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import java.io.ByteArrayOutputStream
import java.awt.image.BufferedImage
import javax.imageio.ImageIO

@RunWith(classOf[JUnitRunner])
class ComputeImageSizeTest extends FunSuite {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed.matchbox

import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@
* limitations under the License.
*/

package io.archivesunleashed.matchbox
package io.archivesunleashed.matchbox

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import java.io.IOException
import java.io.IOException

@RunWith(classOf[JUnitRunner])
class ExtractBoilerpipeTextTest extends FunSuite {
var text = """<p>Text with a boiler plate.<p>
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class ExtractBoilerPipeTextTest extends FunSuite {
var text = """<p>Text with a boiler plate.<p>
<footer>Copyright 2017</footer>"""
var boiler = """Copyright 2017"""
test ("Collects boilerpip") {
assert (ExtractBoilerpipeText (text) == boiler)
assert (ExtractBoilerpipeText ("") == Nil)
assert (ExtractBoilerpipeText ("All Rights Reserved.") == Nil)
val caught = intercept[IOException] {ExtractBoilerpipeText (null)}
assert (caught.getMessage == "Caught exception processing input row java.lang.NullPointerException")
}
}
var boiler = """Copyright 2017"""

test("Collects boilerpip") {
assert(ExtractBoilerpipeText(text) == boiler)
assert(ExtractBoilerpipeText("") == Nil)
assert(ExtractBoilerpipeText("All Rights Reserved.") == Nil)
val caught = intercept[IOException] {
ExtractBoilerpipeText(null)
}
assert(caught.getMessage == "Caught exception processing input row java.lang.NullPointerException")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed.matchbox

import io.archivesunleashed.matchbox.ExtractDate.DateComponent._
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import io.archivesunleashed.matchbox.ExtractDate.DateComponent._

@RunWith(classOf[JUnitRunner])
class ExtractDateTest extends FunSuite {
Expand All @@ -34,10 +35,10 @@ class ExtractDateTest extends FunSuite {
}

test("more perfect") {
assert(ExtractDate("20151204", YYYY) == "20151204".substring(0,4))
assert(ExtractDate("20151204", MM) == "20151204".substring(4,6))
assert(ExtractDate("20151204", DD) == "20151204".substring(6,8))
assert(ExtractDate("20151204", YYYYMM) == "20151204".substring(0,6))
assert(ExtractDate("20151204", YYYYMMDD) == "20151204".substring(0,8))
assert(ExtractDate("20151204", YYYY) == "20151204".substring(0, 4))
assert(ExtractDate("20151204", MM) == "20151204".substring(4, 6))
assert(ExtractDate("20151204", DD) == "20151204".substring(6, 8))
assert(ExtractDate("20151204", YYYYMM) == "20151204".substring(0, 6))
assert(ExtractDate("20151204", YYYYMMDD) == "20151204".substring(0, 8))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed.matchbox

import org.junit.runner.RunWith
Expand All @@ -38,6 +39,7 @@ class ExtractDomainTest extends FunSuite {
case (link, domain) => assert(ExtractDomain(link) == domain)
}
}

test("withBase") {
data2.foreach {
case (link, base, domain) => assert(ExtractDomain(link, base) == domain)
Expand All @@ -48,5 +50,4 @@ class ExtractDomainTest extends FunSuite {
assert(ExtractDomain(null) == null)
assert(ExtractDomain("index.html", null) == null)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed.matchbox

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class ExtractHashtagTest extends FunSuite {
class ExtractHashtagsTest extends FunSuite {
test("simple") {
val tweet = "Here are #some #hashtags #TeSTing"
val extracted = ExtractHashtags(tweet).toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed.matchbox

import java.io.IOException

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import java.io.IOException

@RunWith(classOf[JUnitRunner])
class ExtractImageLinksTest extends FunSuite {
Expand Down Expand Up @@ -48,6 +50,8 @@ class ExtractImageLinksTest extends FunSuite {
assert(ExtractImageLinks("", "") == Nil)
// Need way of creating an exception here
val invalid = null
intercept[IOException] { ExtractImageLinks (invalid, fragment)}
intercept[IOException] {
ExtractImageLinks(invalid, fragment)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.archivesunleashed.matchbox

import java.io.IOException

import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

import scala.collection.mutable
import java.io.IOException

@RunWith(classOf[JUnitRunner])
class ExtractLinksTest extends FunSuite {
Expand Down Expand Up @@ -51,6 +54,5 @@ class ExtractLinksTest extends FunSuite {
assert(ExtractLinks("", "", "http://www.foobar.org/index.html") == mutable.MutableList[(String, String, String)]())
// invalid url should throw exception - need more information here
intercept[IOException] { ExtractLinks("", null, "FROTSTEDwww.foobar.org/index.html") }

}
}
Loading