Replace yahoo finance to stooq (#131)

Old code is dropped to separated provider
This commit is contained in:
2017-12-15 02:01:34 +03:00
parent eb911551eb
commit e5a9e99438
134 changed files with 1213 additions and 1597 deletions

View File

@ -59,11 +59,11 @@ double AWTestLibrary::randomDouble()
QPair<QString, QString> AWTestLibrary::randomFilenames()
{
QString fileName = QString("%1/").arg(
QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QString writeFileName = QString("%1/awesomewidgets/tmp/")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
QString fileName
= QString("%1/").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QString writeFileName
= QString("%1/awesomewidgets/tmp/")
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation));
QString name = randomString(1, 20);
fileName += name;

View File

@ -37,9 +37,7 @@ void TestAbstractFormatter::cleanupTestCase()
}
void TestAbstractFormatter::test_values()
{
}
void TestAbstractFormatter::test_values() {}
void TestAbstractFormatter::test_type()

View File

@ -40,8 +40,7 @@ void TestAWBugReporter::cleanupTestCase()
void TestAWBugReporter::test_generateText()
{
data = AWTestLibrary::randomStringList(4);
QString output
= plugin->generateText(data.at(0), data.at(1), data.at(2), data.at(3));
QString output = plugin->generateText(data.at(0), data.at(1), data.at(2), data.at(3));
for (auto &string : data)
QVERIFY(output.contains(string));
@ -51,9 +50,8 @@ void TestAWBugReporter::test_generateText()
void TestAWBugReporter::test_sendBugReport()
{
QSignalSpy spy(plugin, SIGNAL(replyReceived(int, QString &)));
plugin->sendBugReport(
AWTestLibrary::randomString(),
plugin->generateText(data.at(0), data.at(1), data.at(2), data.at(3)));
plugin->sendBugReport(AWTestLibrary::randomString(),
plugin->generateText(data.at(0), data.at(1), data.at(2), data.at(3)));
QVERIFY(spy.wait(5000));
QVariantList arguments = spy.takeFirst();

View File

@ -56,8 +56,7 @@ void TestAWConfigHelper::test_exportConfiguration()
void TestAWConfigHelper::test_importConfiguration()
{
QVariantMap imported
= plugin->importConfiguration(filename, true, true, true);
QVariantMap imported = plugin->importConfiguration(filename, true, true, true);
QVariantMap converted;
for (auto &key : map.keys())
converted[key] = map.value(key);

View File

@ -30,9 +30,7 @@ void TestAWKeyCache::initTestCase()
}
void TestAWKeyCache::cleanupTestCase()
{
}
void TestAWKeyCache::cleanupTestCase() {}
QTEST_MAIN(TestAWKeyCache);

View File

@ -175,16 +175,15 @@ void TestAWKeys::test_dbus()
QDBusConnection bus = QDBusConnection::sessionBus();
// check if there is active sessions first
QDBusMessage sessions = QDBusMessage::createMethodCall(
AWDBUS_SERVICE, AWDBUS_PATH, AWDBUS_SERVICE, "ActiveServicess");
QDBusMessage sessions = QDBusMessage::createMethodCall(AWDBUS_SERVICE, AWDBUS_PATH,
AWDBUS_SERVICE, "ActiveServicess");
QDBusMessage sessionsResponse = bus.call(sessions, QDBus::BlockWithGui);
if (sessionsResponse.arguments().isEmpty())
QSKIP("No active sessions found, skip DBus tests");
// dbus checks
QDBusMessage request = QDBusMessage::createMethodCall(
QString("%1.i%2").arg(AWDBUS_SERVICE).arg(id), AWDBUS_PATH,
AWDBUS_SERVICE, "WhoAmI");
QString("%1.i%2").arg(AWDBUS_SERVICE).arg(id), AWDBUS_PATH, AWDBUS_SERVICE, "WhoAmI");
// send message to dbus
QDBusMessage response = bus.call(request, QDBus::BlockWithGui);

View File

@ -30,9 +30,7 @@ void TestAWPatternFunctions::initTestCase()
}
void TestAWPatternFunctions::cleanupTestCase()
{
}
void TestAWPatternFunctions::cleanupTestCase() {}
void TestAWPatternFunctions::test_findFunctionCalls()
@ -40,11 +38,9 @@ void TestAWPatternFunctions::test_findFunctionCalls()
QString name = QString("aw_%1").arg(AWTestLibrary::randomString(1, 10));
QString code = AWTestLibrary::randomString(1, 20);
QStringList args = AWTestLibrary::randomStringList(20);
QString function
= QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code);
QString function = QString("$%1<%2>{{%3}}").arg(name).arg(args.join(',')).arg(code);
QString pattern = AWTestLibrary::randomString() + function
+ AWTestLibrary::randomString();
QString pattern = AWTestLibrary::randomString() + function + AWTestLibrary::randomString();
QList<AWPatternFunctions::AWFunction> found
= AWPatternFunctions::findFunctionCalls(name, pattern);
@ -69,10 +65,8 @@ void TestAWPatternFunctions::test_findKeys()
auto keys = AWTestLibrary::randomSelect(allKeys);
auto bars = AWTestLibrary::randomSelect(allKeys);
std::for_each(bars.begin(), bars.end(),
[](QString &bar) { bar.prepend("bar"); });
QString pattern
= QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $"));
std::for_each(bars.begin(), bars.end(), [](QString &bar) { bar.prepend("bar"); });
QString pattern = QString("$%1 $%2").arg(keys.join(" $")).arg(bars.join(" $"));
allKeys.append(bars);
allKeys.sort();
@ -80,11 +74,9 @@ void TestAWPatternFunctions::test_findKeys()
keys.sort();
bars.sort();
QStringList foundKeys
= AWPatternFunctions::findKeys(pattern, allKeys, false);
QStringList foundKeys = AWPatternFunctions::findKeys(pattern, allKeys, false);
foundKeys.sort();
QStringList foundBars
= AWPatternFunctions::findKeys(pattern, allKeys, true);
QStringList foundBars = AWPatternFunctions::findKeys(pattern, allKeys, true);
foundBars.sort();
QCOMPARE(foundKeys, keys);
@ -95,8 +87,7 @@ void TestAWPatternFunctions::test_findKeys()
void TestAWPatternFunctions::test_findLambdas()
{
QStringList lambdas = AWTestLibrary::randomStringList(20);
QString pattern = AWTestLibrary::randomString()
+ QString("${{%1}}").arg(lambdas.join("}}${{"))
QString pattern = AWTestLibrary::randomString() + QString("${{%1}}").arg(lambdas.join("}}${{"))
+ AWTestLibrary::randomString();
QCOMPARE(AWPatternFunctions::findLambdas(pattern), lambdas);
@ -108,13 +99,11 @@ void TestAWPatternFunctions::test_expandTemplates()
int firstValue = AWTestLibrary::randomInt();
int secondValue = AWTestLibrary::randomInt();
int result = firstValue + secondValue;
QString code
= QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue);
QString code = QString("$template{{%1+%2}}").arg(firstValue).arg(secondValue);
QString prefix = AWTestLibrary::randomString();
QString pattern = prefix + code;
QCOMPARE(AWPatternFunctions::expandTemplates(pattern),
QString("%1%2").arg(prefix).arg(result));
QCOMPARE(AWPatternFunctions::expandTemplates(pattern), QString("%1%2").arg(prefix).arg(result));
}

View File

@ -49,15 +49,13 @@ void TestBatterySource::test_battery()
QSKIP("No battery found, test will be skipped");
QStringList batteries = source->sources();
std::for_each(batteries.begin(), batteries.end(),
[this](const QString bat) {
QVariant value = source->data(bat);
if (bat == "battery/ac")
QCOMPARE(value.type(), QVariant::Bool);
else
QVERIFY((value.toFloat() >= battery.first)
&& (value.toFloat() <= battery.second));
});
std::for_each(batteries.begin(), batteries.end(), [this](const QString bat) {
QVariant value = source->data(bat);
if (bat == "battery/ac")
QCOMPARE(value.type(), QVariant::Bool);
else
QVERIFY((value.toFloat() >= battery.first) && (value.toFloat() <= battery.second));
});
}

View File

@ -28,8 +28,7 @@
void TestAWDateTimeFormatter::initTestCase()
{
AWTestLibrary::init();
format
= AWTestLibrary::randomSelect(QString(TIME_KEYS).split(',')).join(' ');
format = AWTestLibrary::randomSelect(QString(TIME_KEYS).split(',')).join(' ');
formatter = new AWDateTimeFormatter(nullptr);
formatter->setFormat(format);

View File

@ -64,8 +64,8 @@ void TestExtQuotes::test_run()
for (auto &type : types) {
QCOMPARE(firstValue[extQuotes->tag(type)].toDouble(), 0.0);
QVERIFY((cache[type].toDouble() > price.first)
&& (cache[type].toDouble() < price.second));
QVERIFY((cache[type].toDouble() >= price.first)
&& (cache[type].toDouble() <= price.second));
}
}
@ -84,9 +84,7 @@ void TestExtQuotes::test_derivatives()
values[type] = arguments.at(0).toHash()[extQuotes->tag(type)];
for (auto &type : types) {
QCOMPARE(arguments.at(0)
.toHash()[extQuotes->tag(QString("%1chg").arg(type))]
.toDouble(),
QCOMPARE(arguments.at(0).toHash()[extQuotes->tag(QString("%1chg").arg(type))].toDouble(),
(values[type].toDouble() - cache[type].toDouble()));
}
}

View File

@ -42,12 +42,10 @@ private slots:
private:
ExtQuotes *extQuotes = nullptr;
QVariantHash cache;
QString ticker = "EURUSD=X";
QStringList types = QStringList() << "ask"
<< "bid"
<< "price";
QString ticker = "EURUSD";
QStringList types = {"price", "volume"};
// we assume that price will not be differ more than in 2 times
QPair<double, double> price = QPair<double, double>(0.5, 2.0);
QPair<double, double> price = QPair<double, double>(0.0, 2.0);
};

View File

@ -64,8 +64,7 @@ void TestExtUpgrade::test_run()
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(firstValue[extUpgrade->tag("pkgcount")].toInt(), 0);
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(),
randomStrings.count());
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), randomStrings.count());
}
@ -95,8 +94,7 @@ void TestExtUpgrade::test_filter()
// check values
QVERIFY(spy.wait(5000));
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(),
filters.count());
QCOMPARE(arguments.at(0).toHash()[extUpgrade->tag("pkgcount")].toInt(), filters.count());
}

View File

@ -88,8 +88,7 @@ void TestExtWeather::test_image()
// check values
QVERIFY(spy.wait(5000));
QVariantHash arguments = spy.takeFirst().at(0).toHash();
QVERIFY(
arguments[extWeather->tag("weather")].toString().startsWith("<img"));
QVERIFY(arguments[extWeather->tag("weather")].toString().startsWith("<img"));
}
@ -120,15 +119,12 @@ void TestExtWeather::run()
QVariantHash arguments = spy.takeFirst().at(0).toHash();
QEXPECT_FAIL("", "WeatherID should not be 0", Continue);
QCOMPARE(arguments[extWeather->tag("weatherId")].toInt(), 0);
QVERIFY(
(arguments[extWeather->tag("humidity")].toInt() >= humidity.first)
&& (arguments[extWeather->tag("humidity")].toInt() <= humidity.second));
QVERIFY(
(arguments[extWeather->tag("pressure")].toInt() > pressure.first)
&& (arguments[extWeather->tag("pressure")].toInt() < pressure.second));
QVERIFY(
(arguments[extWeather->tag("temperature")].toFloat() > temp.first)
&& (arguments[extWeather->tag("temperature")].toFloat() < temp.second));
QVERIFY((arguments[extWeather->tag("humidity")].toInt() >= humidity.first)
&& (arguments[extWeather->tag("humidity")].toInt() <= humidity.second));
QVERIFY((arguments[extWeather->tag("pressure")].toInt() > pressure.first)
&& (arguments[extWeather->tag("pressure")].toInt() < pressure.second));
QVERIFY((arguments[extWeather->tag("temperature")].toFloat() > temp.first)
&& (arguments[extWeather->tag("temperature")].toFloat() < temp.second));
// image should be only one symbol here
if (extWeather->jsonMapFile().isEmpty())
QSKIP("No json map found for weather, skip image test");

View File

@ -37,9 +37,7 @@ void TestAWFloatFormatter::cleanupTestCase()
}
void TestAWFloatFormatter::test_values()
{
}
void TestAWFloatFormatter::test_values() {}
void TestAWFloatFormatter::test_count()
@ -140,8 +138,7 @@ void TestAWFloatFormatter::test_multiplier()
// test
double value = AWTestLibrary::randomDouble();
QCOMPARE(formatter->convert(value),
QString::number(value * multiplier, 'f', 6));
QCOMPARE(formatter->convert(value), QString::number(value * multiplier, 'f', 6));
// reset
formatter->setMultiplier(1.0);
@ -157,8 +154,7 @@ void TestAWFloatFormatter::test_summand()
// test
double value = AWTestLibrary::randomDouble();
QCOMPARE(formatter->convert(value),
QString::number(value + summand, 'f', 6));
QCOMPARE(formatter->convert(value), QString::number(value + summand, 'f', 6));
// reset
formatter->setSummand(1.0);

View File

@ -30,10 +30,10 @@ void TestHDDTemperatureSource::initTestCase()
devices = HDDTemperatureSource::allHdd();
QVERIFY(devices.count() > 0);
hddtempSource = new HDDTemperatureSource(
this, QStringList() << devices.join(',') << hddtempCmd);
smartctlSource = new HDDTemperatureSource(
this, QStringList() << devices.join(',') << smartctlCmd);
hddtempSource
= new HDDTemperatureSource(this, QStringList() << devices.join(',') << hddtempCmd);
smartctlSource
= new HDDTemperatureSource(this, QStringList() << devices.join(',') << smartctlCmd);
}
@ -57,8 +57,7 @@ void TestHDDTemperatureSource::test_sources()
void TestHDDTemperatureSource::test_hddtemp()
{
std::for_each(devices.begin(), devices.end(), [this](QString device) {
QSignalSpy spy(hddtempSource,
SIGNAL(dataReceived(const QVariantHash &)));
QSignalSpy spy(hddtempSource, SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = hddtempSource->data(device).toFloat();
QVERIFY(spy.wait(5000));
@ -75,8 +74,7 @@ void TestHDDTemperatureSource::test_hddtemp()
void TestHDDTemperatureSource::test_smartctl()
{
std::for_each(devices.begin(), devices.end(), [this](QString &device) {
QSignalSpy spy(smartctlSource,
SIGNAL(dataReceived(const QVariantHash &)));
QSignalSpy spy(smartctlSource, SIGNAL(dataReceived(const QVariantHash &)));
float firstValue = smartctlSource->data(device).toFloat();
QVERIFY(spy.wait(5000));

View File

@ -73,8 +73,7 @@ void TestAWListFormatter::test_filter()
value.sort();
formatter->setFilter(QString("(^%1$)").arg(filters.join("$|^")));
QCOMPARE(formatter->convert(value).split(separator).count(),
filters.count());
QCOMPARE(formatter->convert(value).split(separator).count(), filters.count());
}

View File

@ -37,9 +37,7 @@ void TestAWNoFormatter::cleanupTestCase()
}
void TestAWNoFormatter::test_values()
{
}
void TestAWNoFormatter::test_values() {}
void TestAWNoFormatter::test_conversion()

View File

@ -30,9 +30,7 @@ void TestPlayerSource::initTestCase()
}
void TestPlayerSource::cleanupTestCase()
{
}
void TestPlayerSource::cleanupTestCase() {}
void TestPlayerSource::_test_sources(const PlayerSource *_source)
@ -57,8 +55,7 @@ void TestPlayerSource::test_buildString()
void TestPlayerSource::test_stripString()
{
QString str
= PlayerSource::buildString("", AWTestLibrary::randomString(1, 40), 20);
QString str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 40), 20);
QCOMPARE(str.count(), 20);
str = PlayerSource::buildString("", AWTestLibrary::randomString(1, 10), 20);
@ -68,9 +65,8 @@ void TestPlayerSource::test_stripString()
void TestPlayerSource::test_autoMpris()
{
QStringList args(QStringList()
<< "mpris" << mpdAddress << QString::number(mpdPort)
<< "auto" << QString::number(10));
QStringList args(QStringList() << "mpris" << mpdAddress << QString::number(mpdPort) << "auto"
<< QString::number(10));
PlayerSource *source = new PlayerSource(this, args);
bool empty = source->getAutoMpris().isEmpty();
@ -83,9 +79,8 @@ void TestPlayerSource::test_autoMpris()
void TestPlayerSource::test_mpd()
{
QStringList args(QStringList()
<< "mpd" << mpdAddress << QString::number(mpdPort)
<< "auto" << QString::number(10));
QStringList args(QStringList() << "mpd" << mpdAddress << QString::number(mpdPort) << "auto"
<< QString::number(10));
PlayerSource *source = new PlayerSource(this, args);
_test_sources(source);
@ -104,16 +99,14 @@ void TestPlayerSource::test_mpd()
if (secondValue["player/title"].toString() == "unknown")
QSKIP("No mpd found");
QVERIFY(secondValue["player/progress"].toInt()
< secondValue["player/duration"].toInt());
QVERIFY(secondValue["player/progress"].toInt() < secondValue["player/duration"].toInt());
}
void TestPlayerSource::test_mpris()
{
QStringList args(QStringList()
<< "mpris" << mpdAddress << QString::number(mpdPort)
<< "auto" << QString::number(10));
QStringList args(QStringList() << "mpris" << mpdAddress << QString::number(mpdPort) << "auto"
<< QString::number(10));
PlayerSource *source = new PlayerSource(this, args);
_test_sources(source);

View File

@ -37,9 +37,7 @@ void TestAWStringFormatter::cleanupTestCase()
}
void TestAWStringFormatter::test_values()
{
}
void TestAWStringFormatter::test_values() {}
void TestAWStringFormatter::test_count()